/** * Get the point right between two other points (in spherical sense, so the result has the middle abs of gps1 and gps2) */ template<typename T> Spherical<T> calculateCenter(const Spherical<T>& gps1, const Spherical<T>& gps2) { Cartesian<T> cartesian1 = sphericalToCartesian(gps1) / 2; Cartesian<T> cartesian2 = sphericalToCartesian(gps2) / 2; Spherical<T> newPoint = cartesianToSpherical(cartesian1 + cartesian2); return scaleTo(newPoint, (gps1.z + gps2.z) / 2); }
void DepthComplexity3D::writeRaysSpherical(std::ostream& out, int k) { assert(_computeGoodRays); long long unsigned int total = 0; for(int i = 0 ; i <= k ; ++i) { const std::vector<Segment> & _rays = goodRays(maximum()-i); total += _rays.size(); } out << total << "\n"; /* Simple spherical coordinates for(int i = 0 ; i <= k ; ++i) { const std::vector<Segment> & _rays = goodRays(maximum()-i); std::vector<Segment>::const_iterator ite = _rays.begin(); std::vector<Segment>::const_iterator end = _rays.end(); for (; ite != end; ++ite) { double a, b, c, d; double x1 = ite->a.x, x2 = ite->b.x, y1 = ite->a.y, y2 = ite->b.y, z1 = ite->a.z, z2 = ite->b.z; a = atan2(y1, x1); b = atan2(z1, sqrt(x1*x1 + y1*y1)); c = atan2(y2, x2); d = atan2(z2, sqrt(x2*x2 + y2*y2)); out << a << " " << b << " " << c << " " << d << " " << maximum()-i << "\n"; } } */ BoundingBox aabb = _mesh->aabb; Sphere sph; sph.center = aabb.center(); sph.radius = aabb.extents().length()/2; // Coordinates of intersection with bounding sphere for(int i = 0 ; i <= k ; ++i) { const std::vector<Segment> & _rays = goodRays(maximum()-i); std::vector<Segment>::const_iterator ite = _rays.begin(); std::vector<Segment>::const_iterator end = _rays.end(); for (; ite != end; ++ite) { vec3d f, s; assert(segmentSphereIntersection3D(*ite,sph,f,s)); f = cartesianToSpherical(f); s = cartesianToSpherical(s); out << f.y << " " << f.z << " " << s.y << " " << s.z << " " << maximum()-i << "\n"; } } }
void CircularTrajectory::setPosition(const ofVec3f& position) { float e, h; cartesianToSpherical(position, &e, &h); initWithElevationHeading(e, h); }
MStatus sphericalBlendShape::deform(MDataBlock& data, MItGeometry& itGeo, const MMatrix& mat, unsigned int geomIndex) { MStatus status = MS::kSuccess; float env = data.inputValue(envelope).asFloat(); if (env <= 0.0f) { return MS::kSuccess; } MMatrix spaceMatrix = data.inputValue(aSpaceMatrix).asMatrix(); short poleAxis = data.inputValue(aPoleAxis).asShort(); short seamAxis = data.inputValue(aSeamAxis).asShort(); short method = data.inputValue(aMethod).asShort(); MMatrix warpMatrix = data.inputValue(aWarpMatrix).asMatrix(); MTransformationMatrix warpTransMatrix(warpMatrix); MPoint warpPoint = warpTransMatrix.getTranslation(MSpace::kWorld); status = checkPoleAndSeam(poleAxis, seamAxis); CHECK_MSTATUS_AND_RETURN_IT(status); MMatrix invGeoMatrix = mat.inverse(); MMatrix invSpaceMatrix = spaceMatrix.inverse(); MPointArray defPoints; MPoint* defPoint; MPoint inPoint, returnPoint; itGeo.allPositions(defPoints); unsigned int count = defPoints.length(); unsigned int i; switch(method) { // XYZ to Spherical case 0: for (i=0; i<count; i++) { defPoint = &defPoints[i]; inPoint = *defPoint; // bring the point into world space inPoint *= invGeoMatrix; // bring into local space of the input matrix inPoint *= invSpaceMatrix; cartesianToSpherical(inPoint, poleAxis, seamAxis, warpPoint, returnPoint); // bring the point back into world space returnPoint *= spaceMatrix; // bring the point back into local space returnPoint *= mat; lerp(*defPoint, returnPoint, env, *defPoint); } break; case 1: for (i=0; i<count; i++) { defPoint = &defPoints[i]; inPoint = *defPoint; // bring the point into world space inPoint *= invGeoMatrix; // bring into local space of the input matrix inPoint *= invSpaceMatrix; sphericalToCartesian(inPoint, poleAxis, seamAxis, warpPoint, returnPoint); // bring the point back into world space returnPoint *= spaceMatrix; // bring the point back into local space returnPoint *= mat; lerp(*defPoint, returnPoint, env, *defPoint); } break; } itGeo.setAllPositions(defPoints); return MS::kSuccess; }
Matrix<qreal, 3, 1> cartesianToSpherical(const Matrix<qreal, 3, 1> &xyz) { Matrix<qreal, 3, 1> x0y0z0(0., 0., 0.); return cartesianToSpherical(xyz, x0y0z0); }