private void setVerticalTranslationVector(){ double y = Math.cos(Math.toRadians(this.rotation.y)); double yz = Math.sin(Math.toRadians(this.rotation.y)); translationVectorV = new Vector3d(0, y, yz); translationVectorV.normalize(); }
private void setHorizontalTranslationVector() { double x = Math.cos(Math.toRadians(this.rotation.x)); double xz = Math.sin(Math.toRadians(this.rotation.x)); double y = xz * Math.sin(Math.toRadians(this.rotation.y)); double yz = xz * Math.cos(Math.toRadians(this.rotation.y)); translationVectorH = new Vector3d(x, y, yz); translationVectorH.normalize(); }
vec.sub(new Vector3d(item.posX, item.posY, item.posZ)); vec.normalize(); vec.scale(strength);
private static void rotate(Vector3d vSrc, Vector3d axis, double angle, Vector3d vDst) { axis.normalize(); vDst.x = axis.x * (axis.x * vSrc.x + axis.y * vSrc.y + axis.z * vSrc.z) * (1 - Math.cos(angle)) + vSrc.x * Math.cos(angle) + (-axis.z * vSrc.y + axis.y * vSrc.z) * Math.sin(angle); vDst.y = axis.y * (axis.x * vSrc.x + axis.y * vSrc.y + axis.z * vSrc.z) * (1 - Math.cos(angle)) + vSrc.y * Math.cos(angle) + (axis.z * vSrc.x - axis.x * vSrc.z) * Math.sin(angle); vDst.z = axis.z * (axis.x * vSrc.x + axis.y * vSrc.y + axis.z * vSrc.z) * (1 - Math.cos(angle)) + vSrc.z * Math.cos(angle) + (-axis.y * vSrc.x + axis.x * vSrc.y) * Math.sin(angle); }
private static void rotate(Vector3d vSrc, Vector3d axis, double angle, Vector3d vDst) { axis.normalize(); vDst.x = axis.x * (axis.x * vSrc.x + axis.y * vSrc.y + axis.z * vSrc.z) * (1 - Math.cos(angle)) + vSrc.x * Math.cos(angle) + (-axis.z * vSrc.y + axis.y * vSrc.z) * Math.sin(angle); vDst.y = axis.y * (axis.x * vSrc.x + axis.y * vSrc.y + axis.z * vSrc.z) * (1 - Math.cos(angle)) + vSrc.y * Math.cos(angle) + (axis.z * vSrc.x - axis.x * vSrc.z) * Math.sin(angle); vDst.z = axis.z * (axis.x * vSrc.x + axis.y * vSrc.y + axis.z * vSrc.z) * (1 - Math.cos(angle)) + vSrc.z * Math.cos(angle) + (-axis.y * vSrc.x + axis.x * vSrc.y) * Math.sin(angle); }
/** Normalize the ECF vector */ public Vector3d getUnitVector() { final Vector3d unitVec = new Vector3d(ecfVector); unitVec.normalize(); return unitVec; }
/** * Computes the vector going from the first to the second endpoint of this line segment. * * @param normalize whether the direction vector is to be normalized. * @param directionToPack vector in which the direction is stored. Modified. */ public void getDirection(boolean normalize, Vector3d directionToPack) { directionToPack.sub(secondEndpoint, firstEndpoint); if (normalize) directionToPack.normalize(); }
//ship heading (already calculated) Vector3f heading /* = ... */; heading.normalize(); //direction of enemy ship relative to ours Vector3d direction = new Vector3f(enemy.x - ship.x, enemy.y - ship.y, enemy.z - ship.z); direction.normalize(); //angle between vectors float angle = heading.angle(direction);
public static Vector3d generateRandomVector(Random random, double length) { Vector3d ret = generateRandomVector(random); ret.normalize(); ret.scale(length); return ret; }
private void calcCenters() { for (Point3d p : originalCenters) { Point3d c = new Point3d(p); c.sub(centroid); centers.add(c); Vector3d v = new Vector3d(c); v.normalize(); unitVectors.add(v); } }
public static RevoluteJoint addRandomRevoluteJoint(String name, Vector3d jointAxis, Random random, RigidBody predecessor) { Vector3d jointOffset = RandomTools.generateRandomVector(random); jointAxis.normalize(); RevoluteJoint ret = ScrewTools.addRevoluteJoint(name, predecessor, jointOffset, jointAxis); return ret; }
public void getRay(Vector3d rayToPack, int rayIndex) { MathTools.checkIfInRange(rayIndex, 0, numberOfRays - 1); rayToPack.sub(sphereOrigin, pointsOnSphere[rayIndex]); rayToPack.normalize(); }
@Override protected void orthogonalProjectionShapeFrame(Point3d point) { temporaryVector.set(point); double distance = temporaryVector.length(); if (distance >= Epsilons.ONE_TRILLIONTH) { temporaryVector.normalize(); temporaryVector.scale(radius); point.set(temporaryVector); } }
protected final void makeNormal() { normal = new Vector3d(); normal.cross(row, column); normal.normalize(); normalArray = new double[3]; normal.get(normalArray); // depends of vector system (right/left-handed system): normalArray[2] = normalArray[2] * -1 normal = new Vector3d(normalArray); }
public Vector3d getNormalizedEarthTangentVector(final double azimuth) { // TODO: rewrite this to use real math instead of this silly difference final EarthVector nextEV = findPoint(1, azimuth); final Vector3d deltaVec = new Vector3d(); deltaVec.sub(nextEV.getVector(), getVector()); deltaVec.normalize(); return deltaVec; }
// Surface 1/3 (x, y, z - one surface for each) Vector3d edge1 = new Vector3d(); Vector3d edge2 = new Vector3d(); Vector3d normal1 = new Vector3d(); // Get the edges, the two edges must be perpendicular to one another. edge1.sub( point0, point1 ); edge2.sub( point0, point4 ); normal1.cross( edge1, edge2 ); normal1.normalize();
public Point3d get3DCoordinatesForSPLigands(IAtom refAtom, IAtomContainer withCoords, double length, double angle) { //logger.debug(" SP Ligands start "+refAtom.getPoint3d()+" "+(withCoords.getAtomAt(0)).getPoint3d()); Vector3d ca = new Vector3d(refAtom.getPoint3d()); ca.sub((withCoords.getAtom(0)).getPoint3d()); ca.normalize(); ca.scale(length); Point3d newPoint = new Point3d(refAtom.getPoint3d()); newPoint.add(ca); return newPoint; }
public static RigidBodyTransform opencvTRtoRigidBodyTransform(Mat rvec, Mat tvec) { Vector3d translation = new Vector3d(tvec.get(0, 0)[0], tvec.get(1, 0)[0], tvec.get(2, 0)[0]); Vector3d axis = new Vector3d(rvec.get(0, 0)[0], rvec.get(1, 0)[0], rvec.get(2, 0)[0]); double angle = axis.length(); axis.normalize(); AxisAngle4d rotation = new AxisAngle4d(axis, angle); RigidBodyTransform transform = new RigidBodyTransform(rotation, translation); return transform; }
private Matrix4d vecMatrixRandom() { final Matrix4d mat = new Matrix4d(); final Vector3d axis = new Vector3d(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble()); axis.normalize(); mat.set(new AxisAngle4d(axis, MathUtils.nextRandomDouble())); final double x = MathUtils.nextRandomDouble(); final double y = MathUtils.nextRandomDouble(); final double z = MathUtils.nextRandomDouble(); translate(mat, x, y, z); return mat; }
@Test public void positivePointPlaneDistanceTest() { // the normal for the Y-Z plane is X Vector3d planeNormal = new Vector3d(XAXIS); planeNormal.normalize(); // an arbitrary point in the Y-Z plane Point3d pointInPlane = new Point3d(0, 1, 1); // make a positive point on the X axis = same direction as the normal Point3d pointToMeasurePos = new Point3d(2, 0, 0); double distancePos = StereoTool.signedDistanceToPlane(planeNormal, pointInPlane, pointToMeasurePos); Assert.assertEquals(2.0, distancePos, 0.1); }