/** * Returns the default reference vector for the alignment of Cn structures * @return */ private Vector3d getReferenceAxisCylic() { // get principal axis vector that is perpendicular to the principal // rotation vector Vector3d vmin = null; double dotMin = 1.0; for (Vector3d v: principalAxesOfInertia) { if (Math.abs(principalRotationVector.dot(v)) < dotMin) { dotMin = Math.abs(principalRotationVector.dot(v)); vmin = new Vector3d(v); } } if (principalRotationVector.dot(vmin) < 0) { vmin.negate(); } return vmin; }
/** * Returns the angle in radians between this vector and the vector * parameter; the return value is constrained to the range [0,PI]. * @param v1 the other vector * @return the angle in radians in the range [0,PI] */ public final double angle(Vector3d v1) { double vDot = this.dot(v1) / ( this.length()*v1.length() ); if( vDot < -1.0) vDot = -1.0; if( vDot > 1.0) vDot = 1.0; return((double) (Math.acos( vDot ))); }
protected static final double getAngle(final Vector3d vec1, final Vector3d vec2) { return Math.acos(vec1.dot(vec2) / (vec1.length() * vec2.length())); }
/** * Given a normalized normal for a plane, any point in that plane, and * a point, will return the distance between the plane and that point. * * @param planeNormal the normalized plane normal * @param pointInPlane an arbitrary point in that plane * @param point the point to measure * @return the signed distance to the plane */ public static double signedDistanceToPlane(Vector3d planeNormal, Point3d pointInPlane, Point3d point) { if (planeNormal == null) return Double.NaN; Vector3d pointPointDiff = new Vector3d(); pointPointDiff.sub(point, pointInPlane); return planeNormal.dot(pointPointDiff); }
/** * Compute the distance (km) from this coord to the input coord using vector math (my personal * favorite) * * @param loc The coordinate to compute the distance to */ public double getDistance(final EarthVector loc) { double dist = getEarthRadiusKM() * (Math.acos( ecfVector.dot(loc.getVector()) / (ecfVector.length() * loc.getVector().length()))); if (Double.isNaN(dist) || Double.isInfinite(dist)) { dist = 0; } return dist; }
/** * Projects the Vector 'vector' onto the Vector 'onto'. * * @param onto the Vector to be projected on. * @param vector the Vector to be projected. * @return the projection of 'vector' on 'onto' */ protected static final Vector3d getProjection(final Vector3d onto, final Vector3d vector) { Vector3d projection = new Vector3d(onto); projection.scale(projection.dot(vector) / onto.lengthSquared()); return projection; }
/** * Takes the dot product of this twist and a wrench, resulting in the (reference frame independent) instantaneous power. * @param wrench a wrench that * 1) has an 'onWhat' reference frame that is the same as this twist's 'bodyFrame' reference frame. * 2) is expressed in the same reference frame as this twist * @return the instantaneous power associated with this twist and the wrench */ public double dot(Wrench wrench) { this.bodyFrame.checkReferenceFrameMatch(wrench.getBodyFrame()); this.expressedInFrame.checkReferenceFrameMatch(wrench.getExpressedInFrame()); double power = this.angularPart.dot(wrench.getAngularPart()) + this.linearPart.dot(wrench.getLinearPart()); return power; }
/** * Compute the distance (km) from this coord to the input coord using vector math (my personal * favorite) * * @param loc The coordinate to compute the distance to */ public double getDistanceReverseDirection(final EarthVector loc) { double dist = getEarthRadiusKM() * ((2 * Math.PI) - Math.acos( ecfVector.dot(loc.getVector()) / (ecfVector.length() * loc.getVector().length()))); if (Double.isNaN(dist) || Double.isInfinite(dist)) { dist = 0; } return dist; }
public static double getHeading(ReferenceFrame ankleFrame) { RigidBodyTransform transform = ankleFrame.getTransformToDesiredFrame(worldFrame); Vector3d xVector = new Vector3d(1.0, 0.0, 0.0); transform.transform(xVector); xVector.sub(new Vector3d(0.0, 0.0, -xVector.getZ())); xVector.normalize(); if (Double.isNaN(xVector.getX())) { throw new RuntimeException("FootstepUtils: Footsteps cannot face directly upwards"); } double cosTheta = xVector.dot(new Vector3d(1.0, 0.0, 0.0)); double sinTheta = xVector.dot(new Vector3d(0.0, 1.0, 0.0)); double theta = Math.atan2(sinTheta, cosTheta); return theta; }
/** * Returns the rise of a helix given the subunit centers of two adjacent * subunits and the helix transformation * * @param transformation * helix transformation * @param p1 * center of one subunit * @param p2 * center of an adjacent subunit * @return */ private static double getRise(Matrix4d transformation, Point3d p1, Point3d p2) { AxisAngle4d axis = getAxisAngle(transformation); Vector3d h = new Vector3d(axis.x, axis.y, axis.z); Vector3d p = new Vector3d(); p.sub(p1, p2); return p.dot(h); }
public boolean isPointNearWheel(double x, double y, double z, double fudgeFactor) { tempVector.set(x, y, z); tempVector3.set(1.0, 0.0, 0.0); double dotProduct = tempVector.dot(tempVector3); tempVector2.set(tempVector3); tempVector2.scale(dotProduct); tempVector.sub(tempVector2); double radius = tempVector.length(); return (dotProduct > -BOUNDING_WHEEL_NEAR_X) && (dotProduct < BOUNDING_WHEEL_FAR_X) && (radius < BOUNDING_OUTER_WHEEL_RADIUS - fudgeFactor) && (radius > BOUNDING_INNER_WHEEL_RADIUS + fudgeFactor); }
private Vector3d getReferenceAxisOctahedral() { for (int i = 0; i < rotationGroup.getOrder(); i++) { AxisAngle4d axisAngle = rotationGroup.getRotation(i).getAxisAngle(); Vector3d v = new Vector3d(axisAngle.x, axisAngle.y, axisAngle.z); double d = v.dot(principalRotationVector); if (rotationGroup.getRotation(i).getFold() == 4) { // the dot product 0 is between to adjacent 4-fold axes if (d > -0.1 && d < 0.1 ) { return v; } } } return null; }
/** * Calculates the Point on the ray that is closest to the center (0, 0, 0). * * @param origin * @param direction * @return the direction vector. */ protected static Point3d getClosestPoint(Point3d origin, Vector3d direction) { Vector3d toCenter = new Vector3d(origin); toCenter.scale(-1); Vector3d projection = getProjection(direction, toCenter); if (projection.dot(direction) < 0) { return null; } Point3d closestPoint = new Point3d(origin); closestPoint.add(projection); return closestPoint; }
private Vector3d getReferenceAxisTetrahedral() { for (int i = 0; i < rotationGroup.getOrder(); i++) { AxisAngle4d axisAngle = rotationGroup.getRotation(i).getAxisAngle(); Vector3d v = new Vector3d(axisAngle.x, axisAngle.y, axisAngle.z); double d = v.dot(principalRotationVector); if (rotationGroup.getRotation(i).getFold() == 3) { // the dot product 0 is between to adjacent 3-fold axes if (d > 0.3 && d < 0.9) { return v; } } } return null; }
private Vector3d getReferenceAxisIcosahedral() { for (int i = 0; i < rotationGroup.getOrder(); i++) { AxisAngle4d axisAngle = rotationGroup.getRotation(i).getAxisAngle(); Vector3d v = new Vector3d(axisAngle.x, axisAngle.y, axisAngle.z); double d = v.dot(principalRotationVector); if (rotationGroup.getRotation(i).getFold() == 5) { // the dot product of 0.447.. is between to adjacent 5-fold axes // if (d > 0.447 && d < 0.448) { if (d > 0.4 && d < 0.5) { return v; } } } return null; }
@Test() public void cod1100784CellAngles() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("1100784.cif"); CIFReader cifReader = new CIFReader(in); IChemFile chemFile = cifReader.read(new ChemFile()); ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal(); Vector3d a = crystal.getA(); Vector3d b = crystal.getB(); Vector3d c = crystal.getC(); double alpha = java.lang.Math.acos(b.dot(c)/(b.length()*c.length()))*180/java.lang.Math.PI; double beta = java.lang.Math.acos(c.dot(a)/(c.length()*a.length()))*180/java.lang.Math.PI; double gamma = java.lang.Math.acos(a.dot(b)/(a.length()*b.length()))*180/java.lang.Math.PI; Assert.assertTrue( java.lang.Math.abs(alpha - 109.1080) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(beta - 98.4090) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(gamma - 102.7470) < 1E-5 ); cifReader.close(); }
private boolean isColinear(IAtom focus, IAtom[] terminals) { Vector3d vec0 = new Vector3d(terminals[0].getPoint3d().x - focus.getPoint3d().x, terminals[0].getPoint3d().y - focus.getPoint3d().y, terminals[0].getPoint3d().z - focus.getPoint3d().z); Vector3d vec1 = new Vector3d(terminals[1].getPoint3d().x - focus.getPoint3d().x, terminals[1].getPoint3d().y - focus.getPoint3d().y, terminals[1].getPoint3d().z - focus.getPoint3d().z); vec0.normalize(); vec1.normalize(); return Math.abs(vec0.dot(vec1) + 1) < 0.05; }
Plane( Point3d p0, Point3d p1, Point3d p2 ) { Vector3d v = new Vector3d( p1 ); v.sub( p0 ); Vector3d u = new Vector3d( p2 ); u.sub( p0 ); n = new Vector3d(); n.cross( v, u ); n.normalize(); A = n.x; B = n.y; C = n.z; Vector3d minusN = new Vector3d( n ); minusN.scale( -1.0 ); D = minusN.dot( new Vector3d( p0 ) ); }
@Override public EditorChangeEvent move(Ray3d moveRay, boolean finish) { Point3d editorOrigin = getEditorOrigin(); Vector3d normal = new Vector3d(getVector()); normal.normalize(); Ray3d arrowRay = new Ray3d(editorOrigin, normal); Point3d closestPointOnBaseRay = Ray3dUtil.closestPointOnBaseRay(moveRay, arrowRay); Vector3d moveVector = Vector3dUtil.fromTo(editorOrigin, closestPointOnBaseRay); double lenghtOnEditor = normal.dot(moveVector); double length = lenghtOnEditor - spotFloatingOffset(moveRay.getPoint()); setLength(length); ArrowEditorChangeEvent event = new ArrowEditorChangeEvent(finish, this, length, closestPointOnBaseRay); raiseEditorChange(event); return event; }