private void accKeyAdd(Vector3d a, Vector3d da, Vector3d drag, double scaleVel) { /* Scaling of acceleration due to modification keys */ nda.scale(scaleVel, da); /* Addition of sufficent acceleration to counteract drag */ nda.sub(drag); /* Summing into overall acceleration */ a.add(nda); }
public void eyePtChanged(final View view) { final Point3d eyePt = getViewPosInLocal(view, root); if (eyePt != null) { final Point3d volRefPt = volume.volRefPt; eyeVec.sub(eyePt, volRefPt); // select the axis with the greatest magnitude int axis = X_AXIS; double value = eyeVec.x; double max = Math.abs(eyeVec.x); if (Math.abs(eyeVec.y) > max) { axis = Y_AXIS; value = eyeVec.y; max = Math.abs(eyeVec.y); } if (Math.abs(eyeVec.z) > max) { axis = Z_AXIS; value = eyeVec.z; max = Math.abs(eyeVec.z); } // select the direction based on the sign of the magnitude final int dir = value > 0.0 ? FRONT : BACK; if ((axis != curAxis) || (dir != curDir)) { curAxis = axis; curDir = dir; axisSwitch.setWhichChild(axisIndex[curAxis][curDir]); } } }
final Point3d eyePt = getViewPosInLocal(view, rootBranchGroup); if (eyePt == null) return; eyeVec.sub(eyePt, refPt);
/** * Translates the view by the specified distances along the x, y and z * direction (of the vworld). * * @param v The distances in x, y and z direction, given in vworld dimensions. */ public void translate(final Vector3d v) { getTranslateTranslation(tmpV); tmpV.sub(v); translateXform.set(tmpV); translateTG.setTransform(translateXform); transformChanged(BehaviorCallback.TRANSLATE, translateXform); }
/** * Transforms the x-direction of the image plate to a normalized vector * representing this direction in the vworld space. * * @param v Vector3d in which the result in stored. * @param ipToVWorld the image plate to vworld transformation. */ public void getXDir(final Vector3d v, final Transform3D ipToVWorld) { origin.set(0, 0, 0); oneInX.set(1, 0, 0); ipToVWorld.transform(oneInX); ipToVWorld.transform(origin); v.sub(oneInX, origin); v.normalize(); }
/** * Returns the square of the minimum distance from the given point to the ray * defined by start, dir. */ static final double ptToRaySquare(Point3d pt, Point3d start, Vector3d dir, Point3d closest) { Vector3d dt = new Vector3d(); dt.sub(pt, start); // Project the point onto the ray double proj = dir.dot(dt); // We projected 'before' the start point, just return the dSquared between // the point and the start if (proj <= 0.0d) { if (closest != null) closest.set(start); return dt.lengthSquared(); } // Project the ray onto itself double raySquared = dir.lengthSquared(); // We projected somewhere along the ray, calculate the closest point dt.scaleAdd(proj / raySquared, dir, start); if (closest != null) closest.set(dt); // return the distance from the point to the closest point on the ray dt.sub(pt, dt); return dt.lengthSquared(); }
/** Minimum distance between point v0 and a line segment defined by points v1 and v2. */ static public final double distancePointToSegment(final Vector3d p, final Vector3d v1, final Vector3d v2) { final Vector3d v = new Vector3d(); v.sub(v2, v1); final Vector3d w = new Vector3d(); w.sub(p, v1); final double c1 = w.dot(v); if (c1 <= 0) return distance(p, v1); final double c2 = v.dot(v); if (c2 <= c1) return distance(p, v2); final double b = c1 / c2; final Vector3d pb = new Vector3d(v); pb.scale(b); pb.add(v1); return distance(p, pb); }
/** * Transforms the y-direction of the image plate to a normalized vector * representing this direction in the vworld space. * * @param v Vector3d in which the result in stored. * @param ipToVWorld the image plate to vworld transformation. */ public void getYDir(final Vector3d v, final Transform3D ipToVWorld) { origin.set(0, 0, 0); oneInY.set(0, 1, 0); ipToVWorld.transform(oneInY); ipToVWorld.transform(origin); v.sub(oneInY, origin); v.normalize(); }
/** * Transforms the z-direction of the image plate to a normalized vector * representing this direction in the vworld space. * * @param v Vector3d in which the result in stored. * @param ipToVWorld the image plate to vworld transformation. */ public void getZDir(final Vector3d v, final Transform3D ipToVWorld) { origin.set(0, 0, 0); oneInZ.set(0, 0, 1); ipToVWorld.transform(oneInZ); ipToVWorld.transform(origin); v.sub(origin, oneInZ); v.normalize(); }
static public final double distancePointToSegmentSq(final Vector3d p, final Vector3d v1, final Vector3d v2) { final Vector3d v = new Vector3d(); v.sub(v2, v1); final Vector3d w = new Vector3d(); w.sub(p, v1); final double c1 = w.dot(v); if (c1 <= 0) return distanceSq(p, v1); final double c2 = v.dot(v); if (c2 <= c1) return distanceSq(p, v2); final double b = c1 / c2; final Vector3d pb = new Vector3d(v); pb.scale(b); pb.add(v1); return distanceSq(p, pb); }
/** * Calculates from the specified axis in image plate coordinate system the * corresponding vector in the vworld coordinate system. */ public void getAxisVworld(final Vector3d axis, final Vector3d axisVW) { canvas.getImagePlateToVworld(ipToVWorld); origin.set(0, 0, 0); oneInX.set(axis); ipToVWorld.transform(oneInX); ipToVWorld.transform(origin); axisVW.sub(oneInX, origin); axisVW.normalize(); }
/** * Transforms the target coordinate system about a center point. * This can be used for rotation and scaling. * * @param target the coordinate system to transform * @param center the center point about which to transform * @param transform the transform to apply */ protected void transformAboutCenter (Transform3D target, Point3d center, Transform3D transform) { // Translate to the center. target.get(v3dTmp) ; v3dTmp.sub(center) ; target.setTranslation(v3dTmp) ; // Apply the transform. target.mul(transform, target) ; // Translate back. target.get(v3dTmp) ; v3dTmp.add(center) ; target.setTranslation(v3dTmp) ; }
sqDist = Utils.ptToRaySquare(pt, origin, direction, iPnt); originToIpnt.sub(iPnt, origin); distance = originToIpnt.length(); radius = Math.tan (cone.getSpreadAngle()) * distance;
sqDist = Distance.pointToRay (pt, origin, direction, iPnt, null); originToIpnt.sub (iPnt, origin); distance = originToIpnt.length(); radius = Math.tan (cone.getSpreadAngle()) * distance;
/** * Reset the orientation and distance of this behavior to the current * values in the ViewPlatform Transform Group */ private void resetView() { Vector3d centerToView = new Vector3d(); targetTG.getTransform( targetTransform ); targetTransform.get( rotMatrix, transVector ); centerToView.sub( transVector, rotationCenter ); distanceFromCenter = centerToView.length(); startDistanceFromCenter = distanceFromCenter; targetTransform.get( rotMatrix ); rotateTransform.set( rotMatrix ); // compute the initial x/y/z offset temp1.set(centerToView); rotateTransform.invert(); rotateTransform.mul(temp1); rotateTransform.get(centerToView); xtrans = centerToView.x; ytrans = centerToView.y; ztrans = centerToView.z; // reset rotMatrix rotateTransform.set( rotMatrix ); }
public void setTransform(final Transform3D transform) { if (contentNode == null) return; final Transform3D t = new Transform3D(); final Point3d c = new Point3d(); contentNode.getCenter(c); final Matrix3f m = new Matrix3f(); transform.getRotationScale(m); t.setRotationScale(m); // One might thing a rotation matrix has no translational // component, however, if the rotation is composed of // translation - rotation - backtranslation, it has indeed. final Vector3d v = new Vector3d(); v.x = -m.m00 * c.x - m.m01 * c.y - m.m02 * c.z + c.x; v.y = -m.m10 * c.x - m.m11 * c.y - m.m12 * c.z + c.y; v.z = -m.m20 * c.x - m.m21 * c.y - m.m22 * c.z + c.z; t.setTranslation(v); localRotate.setTransform(t); final Vector3d v2 = new Vector3d(); transform.get(v2); v2.sub(v); t.set(v2); localTranslate.setTransform(t); }
/** Return true if point intersects with cylinder and the distance is stored in dist. */ boolean intersectCylinder(Point3d pt, PickCylinder cyl, double[] dist) { Point3d origin = new Point3d(); Point3d end = new Point3d(); Vector3d direction = new Vector3d(); Point3d iPnt = new Point3d(); Vector3d originToIpnt = new Vector3d(); // Get cylinder information cyl.getOrigin (origin); cyl.getDirection (direction); double radius = cyl.getRadius (); double sqDist; if (cyl instanceof PickCylinderSegment) { ((PickCylinderSegment)cyl).getEnd (end); sqDist = Utils.ptToSegSquare(pt, origin, end, iPnt); } else { sqDist = Utils.ptToRaySquare(pt, origin, direction, iPnt); } if (sqDist <= radius*radius) { originToIpnt.sub (iPnt, origin); dist[0] = originToIpnt.length(); return true; } return false; }
originToIpnt.sub (iPnt, origin); pi.setDistance (originToIpnt.length()); return true;