/** * \return Angle between this vector and XY plane (horizontal plane). */ double RVector::getAngleToPlaneXY() const { RVector n(0, 0, 1); if (getMagnitude() < 1.0e-4) { return M_PI / 2; } else if ((getDotProduct(*this, n) / (getMagnitude() * 1)) > 1.0) { return 0.0; } else { return M_PI / 2 - acos(getDotProduct(*this, n) / (getMagnitude() * 1)); } }
void saveToXML() { xml.clear(); xml.addChild("SKY"); xml.setTo("SKY"); for (auto it = stars.begin(); it != stars.end(); it++) { ofVec2f p = it->getPosition(); int m = it->getMagnitude(); int id = it->getId(); ofXml star; star.addChild("STAR"); star.setTo("STAR"); star.addChild("POSITION"); star.setTo("POSITION"); star.addValue("X", p.x); star.addValue("Y", p.y); star.setTo("../"); star.addValue("MAGNITUDE", m); star.addValue("ID", id); xml.addXml(star); } xml.save("mySettings.xml"); }
void AssignmentFour::magnitudeDistributionHelper(int n, float32 minX, float32 maxX, float32 minY, float32 maxY, vector<Vector2f> &points) { float32 spread = (float32) (sqrt(n) * 1.2); float32 dx = (maxX - minX) / spread; float32 dy = (maxY - minY) / spread; if (n <= 0) { return; } vector< pair<float32, Vector2f> > magnitudes; for (int xi = 0; xi < n; ++xi) { for (int yi = 0; yi < n; ++yi) { float32 x = minX + xi*dx; float32 y = minY + yi*dy; Vector2f v = makeVector2f(x, y); float32 magnitude = getMagnitude(v); magnitudes.push_back(make_pair(magnitude, v)); } } sort(magnitudes.begin(), magnitudes.end(), [](const pair<float32, Vector2f> &m1, const pair<float32, Vector2f> &m2) -> bool { return m1.first > m2.first; }); for (size_t i = 0; i < (size_t) n; ++i) { points.push_back(magnitudes[i].second); } }
bool VortexParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { if(getBeacon() != NULL) { Matrix BeaconToWorld(getBeacon()->getToWorld()); Vec3f translation, tmp; Quaternion tmp2; BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2); Pnt3f particlePos = System->getPosition(ParticleIndex); Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range { Vec3f particleDirectionFromVortex(particlePos.x() - translation.x(), particlePos.y() - translation.y(), particlePos.z() - translation.z()); particleDirectionFromVortex = particleDirectionFromVortex.cross(getVortexAxis()); particleDirectionFromVortex.normalize(); particleDirectionFromVortex = particleDirectionFromVortex * ((-getMagnitude() * elps)/OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax())); System->setVelocity(particleDirectionFromVortex + System->getVelocity(ParticleIndex),ParticleIndex); } } return false; }
void Vector4::Normalise() { float tempMag = getMagnitude(); x = x / tempMag; y = y / tempMag; z = z / tempMag; a = a / tempMag; }
void OWVector4::normalise() { float mag = getMagnitude(); _x /= mag; _y /= mag; _z /= mag; }
void Quaternion::normalize() { float m = getMagnitude(); w /= m; x /= m; y /= m; z /= m; }
/** * \return A new unit vector with the same direction as this vector. */ RVector RVector::getNormalized() const { double l = getMagnitude(); if (l<RS::PointTolerance) { return RVector::invalid; } return *this / l; }
Vector3 Vector3::getUnitVector() { Vector3 temp; float tempMag = getMagnitude(); temp.x = x / tempMag; temp.y = y / tempMag; temp.z = z / tempMag; return temp; }
void Vector3::normalize() { double mag = getMagnitude(); x = x/mag; y = y/mag; z = z/mag; }
void Vector::saturate(float maximum) { if (getMagnitude() > maximum) { normalize(); multiply(maximum); } }
Vector4 Vector4::getUnitVector() { Vector4 temp; float tempMag = getMagnitude(); temp.x = x / tempMag; temp.y = y / tempMag; temp.z = z / tempMag; temp.a = a / tempMag; return temp; }
void PhaseVocoder::process(double *src, double *mag, double *theta) { FFTShift( m_n, src); m_fft->process(0, src, m_realOut, m_imagOut); getMagnitude( m_n/2, mag, m_realOut, m_imagOut); getPhase( m_n/2, theta, m_realOut, m_imagOut); }
Vector<T, SIZE>& Vector<T, SIZE>::normalize() { float magnitude = getMagnitude(); for (auto m_T : m_Ts) { m_T /= magnitude; } return *this; }
void Vector2::normalise() { float magnitude = getMagnitude(); if (magnitude > 0) { x /= magnitude; y /= magnitude; } }
std::ostream& RadialVelocity::dump(std::ostream& o) const { o << "RadialVelocity[getMagnitude()="; o << common::to_quoted_string(getMagnitude()); o << ", getDirection()="; o << common::to_quoted_string(getDirection()); o << ']'; return o; }
long BigInt::getDigitSum() { int digits = getMagnitude(); long ret = 0; for(int i=0; i<digits; ++i) { ret += (value[i] - '0'); } return ret; }
float AudioSampleBuffer::getMagnitude (const int startSample, const int numSamples) const noexcept { float mag = 0.0f; for (int i = 0; i < numChannels; ++i) mag = jmax (mag, getMagnitude (i, startSample, numSamples)); return mag; }
Vector2f Vector2f::getNormalised(void) const { float magnitude = getMagnitude(); if(magnitude == 0.0f) { return Vector2f(0.0f, 0.0f); } return Vector2f(x / magnitude, y /magnitude); }
math_vector math_vector::rotate(double degrees){ // printf("%g degrees + %g degrees\n",getAngle(),degrees); if (!degrees) return math_vector(x,y); if (degrees==270) return rightAngle(); if (degrees==180) return (*this)*-1; if (degrees==90) return rightAngle()*-1; double angle=getAngle()+degrees; while (angle<0) angle+=360; while (angle>360) angle-=360; return createFromPolar(angle,getMagnitude()); }
void BigInt::reverse() { char* first = &value[0]; char* last = &value[getMagnitude()-1]; while( first < last ) { char tmp = *first; *first = *last; *last = tmp; ++first; --last; } }
/* PUBLIC MEMBER FUNCTIONS */ float Vector2f::getAngle(const Vector2f &v) const { // WARNING: this may not work float length = (getMagnitude() * v.getMagnitude()); if (length == 0.0f) { return 0.0f; } return (float)acos(getDotProduct(v) / length); }
// check if one object has collided with another object // returns true if the two objects have collided bool checkCollision(movableObject& obj1, movableObject& obj2) { vector2 diff = vectorSubtract(obj1.position, obj2.position); float mag = getMagnitude(diff); if(mag > 0 && mag < obj1.height){ // collision obj1.speed = multiplyScalar( getNormal(diff), 5); obj2.speed = multiplyScalar( getNormal(diff), -5); return true; } return false; }
long BigInt::getLong() { int digits = getMagnitude(); long ret = 0; reverse(); for(int i=0; i<digits; ++i) { ret *= 10; ret += (value[i] - '0'); } reverse(); return ret; }
void Vector::normalize() { float magnitude = getMagnitude(); if (magnitude > 0) { x_ /= magnitude; y_ /= magnitude; } else { ROS_WARN("[Vector] Normalizing a zero magnitude vector does not change anything"); } }
ConnectingBone::ConnectingBone(TransformerBone* Tparent, TransformerBone* Tchild) { m_Tparent = Tparent; m_Tchild = Tchild; // Global (will be changed to local later on) m_parentJoint = m_Tparent->m_endJoint; m_childJoint = m_Tchild->m_startJoint; m_foldCoord = m_parentJoint; Vec3f diff = m_childJoint - m_parentJoint; m_foldedLength = getMagnitude(diff); setRotations(); }
const Force::Gravity& Force::Gravity:: setGravityVector(State& state, const Vec3& gravity) const { const Real newg = gravity.norm(); const UnitVec3 newd = newg > 0 ? UnitVec3(gravity/newg, true) : getDownDirection(state); if (getMagnitude(state) != newg || getDownDirection(state) != newd) { getImpl().invalidateForceCache(state); getImpl().updParameters(state).g = newg; getImpl().updParameters(state).d = newd; if (newg == 0) getImpl().updForceCache(state).setToZero(); // must precalculate } return *this; }
const Force::Gravity& Force::Gravity:: setMagnitude(State& state, Real g) const { SimTK_ERRCHK1_ALWAYS(g >= 0, "Force::Gravity::setMagnitude()", "The gravity magnitude g must be nonnegative but was specified as %g.", g); if (getMagnitude(state) != g) { getImpl().invalidateForceCache(state); getImpl().updParameters(state).g = g; if (g == 0) getImpl().updForceCache(state).setToZero(); // must precalculate } return *this; }
//check if two objects have collided with one another, return true if collided bool checkCollision(movableObject& obj1, movableObject& obj2, bool bBall) { vector2 vDifference = vectorSubtract(obj1.v2Position, obj2.v2Position); float fMag = getMagnitude(vDifference); if( fMag > 0 && fMag < obj1.iHeight ) { if( !bBall ) { //collide obj1.v2Speed = multiplyScalar( getNormal(vDifference), 5 ); obj2.v2Speed = multiplyScalar( getNormal(vDifference), -5 ); } return true; } return false; }
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override { // Your audio-processing code goes here! auto buffer = bufferToFill.buffer; GestureInterpretor::audioRMS = buffer->getMagnitude(0, 0, bufferToFill.numSamples); const float* ptr = buffer->getArrayOfReadPointers()[0]; // For more details, see the help for AudioProcessor::getNextAudioBlock() for (int i = 0; i < bufferToFill.numSamples; i++) { GestureInterpretor::audioInBuffer[i] = ptr[i]; } // Right now we are not producing any data, in which case we need to clear the buffer // (to prevent the output of random noise) bufferToFill.clearActiveBufferRegion(); }