/** * 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 ))); }
private boolean projectToPlane(Vector3d projVec, Vector3d planeVec) { double dis = planeVec.dot(projVec); projVec.x = projVec.x - planeVec.x*dis; projVec.y = projVec.y - planeVec.y*dis; projVec.z = projVec.z - planeVec.z*dis; double length = projVec.length(); if (length < EPSILON) { // projVec is parallel to planeVec return false; } projVec.scale(1 / length); return true; }
private boolean projectToPlane(Vector3d projVec, Vector3d planeVec) { double dis = planeVec.dot(projVec); projVec.x = projVec.x - planeVec.x*dis; projVec.y = projVec.y - planeVec.y*dis; projVec.z = projVec.z - planeVec.z*dis; double length = projVec.length(); if (length < EPSILON) { return false; } projVec.scale(1 / length); return true; }
/** In 3D */ static public double distancePointToLine(final double px, final double py, final double pz, final double lx1, final double ly1, final double lz1, final double lx2, final double ly2, final double lz2 ) { final double segment_length = new Vector3d(lx2 - lx1, ly2 - ly1, lz2 - lz1).length(); if (0 == segment_length) return 0; final Vector3d cross = new Vector3d(); cross.cross(new Vector3d(px - lx1, py - ly1, pz - lz1), new Vector3d(px - lx2, py - ly2, pz - lz2)); return cross.length() / segment_length; }
vec0.y = coordinates[i+1].y - coordinates[i].y; vec0.z = coordinates[i+1].z - coordinates[i++].z; if(vec0.length() > 0.0) break; vec1.y = coordinates[j+1].y - coordinates[j].y; vec1.z = coordinates[j+1].z - coordinates[j].z; if(vec1.length() > 0.0) break; pNrm.cross(vec1,vec0); if(pNrm.length() == 0.0) {
if(n1.length() == 0.0) {
vec0.y = coordinates[i+1].y - coordinates[i].y; vec0.z = coordinates[i+1].z - coordinates[i++].z; if (vec0.length() > 0.0) break; vec1.y = coordinates[j+1].y - coordinates[j].y; vec1.z = coordinates[j+1].z - coordinates[j].z; if (vec1.length() > 0.0) break; pNrm.cross(vec1,vec0); if (pNrm.length() == 0.0) {
public void updateFrontBackClip() { zoomTG.getTransform(zoomXform); zoomXform.get(zDir); final double d = zDir.length(); univ.getViewer().getView().setBackClipDistance(5 * d); univ.getViewer().getView().setFrontClipDistance(5 * d / 100); }
distance = originToIpnt.length(); radius = Math.tan (cone.getSpreadAngle()) * distance; if (sqDist <= radius*radius) {
/** * 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 ); }
distance = originToIpnt.length(); radius = Math.tan (cone.getSpreadAngle()) * distance; if (sqDist <= radius*radius) {
/** 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; }
final double distance = centerV.length(); univ.getViewer().getView().setBackClipDistance(5 * distance); univ.getViewer().getView().setFrontClipDistance(5 * distance / 100);
distance = originToIpnt.length(); radius = Math.tan (cone.getSpreadAngle()) * distance; if (sqDistToEdge <= radius*radius) {
pi.setPointCoordinatesVW (pt); originToIpnt.sub (iPnt, origin); pi.setDistance (originToIpnt.length()); return true;
distance = originToIpnt.length(); radius = Math.tan (cone.getSpreadAngle()) * distance; if (sqDistToEdge <= radius*radius) {
pi.setPointCoordinatesVW (iPnt2); originToIpnt.sub (iPnt1, origin); pi.setDistance (originToIpnt.length()); return true;