Vector3d vec0 = new Vector3d(); // Edge vector from point 0 to point 1; Vector3d vec1 = new Vector3d(); // Edge vector from point 0 to point 2 or 3; Vector3d pNrm = new Vector3d(); double pD = 0.0; Vector3d tempV3d = new Vector3d(); 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(vec0,vec1); else pNrm.cross(vec1,vec0); if(pNrm.length() == 0.0) { tempV3d.set(coordinates[0]); pD = pNrm.dot(tempV3d); tempV3d.set(point.location); return ((pD - pNrm.dot(tempV3d)) <= 0);
private void computePlaneEq(Point4d p1, Point4d p2, Point4d p3, Point4d p4, Vector4d planeEq) { tVec1.x = p3.x - p1.x; tVec1.y = p3.y - p1.y; tVec1.z = p3.z - p1.z; tVec2.x = p2.x - p1.x; tVec2.y = p2.y - p1.y; tVec2.z = p2.z - p1.z; tVec3.cross(tVec2, tVec1); tVec3.normalize(); planeEq.x = tVec3.x; planeEq.y = tVec3.y; planeEq.z = tVec3.z; planeEq.w = -(planeEq.x * p1.x + planeEq.y * p1.y + planeEq.z * p1.z); }
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); }
/** 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; }
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; }
Point3d pnt1 = new Point3d(); Point3d pnt2 = new Point3d(); Vector3d vec = new Vector3d(); Vector3d normal = new Vector3d(); Vector3d tmpvec = new Vector3d(); vec.sub(pnt0, pnt1); tmpvec.sub(pnt1, pnt2); normal.cross(vec, tmpvec); normal.normalize(); getCrossValue(pnt1, pnt2, tmpvec); getCrossValue(pnt2, pnt0, tmpvec); area = normal.dot(tmpvec); centroid.x += (pnt0.x + pnt1.x + pnt2.x)* area; centroid.y += (pnt0.y + pnt1.y + pnt2.y)* area;
eyeVec.set(viewPosition); eyeVec.normalize(); vector.cross(eyeVec, zAxis); if (vector.dot(nAxis) > 0.0) { sign = 1.0; } else { double dot = eyeVec.dot(zAxis); eyeVec.set(viewPosition); eyeVec.normalize(); yUp.set(yUpPoint); yUp.sub(viewPosition); yUp.normalize(); vector.cross(eyeVec, zAxis); // vector is cross product double length = vector.length(); double dot = eyeVec.dot(zAxis); double dot = yUp.dot(yAxis); vector.cross(yUp, yAxis); // vector is cross product if (eyeVec.dot(vector) < 0) { angle *= -1;
Vector3d direction = new Vector3d(); Point3d iPnt = new Point3d(); Vector3d originToIpnt = new Vector3d(); sqDist = Utils.ptToRaySquare(pt, origin, direction, iPnt); originToIpnt.sub(iPnt, origin); distance = originToIpnt.length(); radius = Math.tan (cone.getSpreadAngle()) * distance; if (sqDist <= radius*radius) {
/** * 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(); }
Vector3d tempV3D = new Vector3d(); boolean esFlag; Point3d center = new Point3d(); if (tempV3D.length() <= radius) { Vector3d vec0 = new Vector3d(); //Edge vector from point 0 to point 1; Vector3d vec1 = new Vector3d(); //Edge vector from point 0 to point 2 or 3; Vector3d pNrm = new Vector3d(); Vector3d pa = new Vector3d(); Point3d q = new Point3d(); double nLenSq, pqLen, pNrmDotPa, tq; 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(vec0,vec1); nLenSq = pNrm.lengthSquared(); if ( nLenSq == 0.0) { pNrmDotPa = pNrm.dot(pa);
final Vector3d origin = new Vector3d(); final int len = ps.size(); for (final Point3d p : ps) { p.z /= len; for (final Point3d p : ps) origin.add(p); vz.scale(dir[0]); vy.scale(dir[1]); vx.scale(dir[2]); final Vector3d vc_medial = new Vector3d(); vc_medial.cross(vz, vy); final Vector3d vc_dorsal = new Vector3d(); vc_dorsal.cross(vz, vc_medial); final Vector3d vc_dor = new Vector3d(vc_dorsal); vc_dor.add(vy); if (vc_dor.length() < vy.length()) { vc_dorsal.scale(-1); Utils.log("Mirroring Y axis"); v1.normalize(); v1.scale(o_ref[0].length()); v2.normalize(); v2.scale(o_ref[1].length()); v3.normalize(); v3.scale(o_ref[2].length());
/** The sum of all vectors, or what is the same: a vector from first to last points. */ public Vector3d sumVector() { return new Vector3d(x[length-1] - x[0], y[length-1] - y[0], z[length-1] - z[0]); }
Point3d eyePosn = new Point3d(); Point3d mousePosn = new Point3d(); Vector3d mouseVec = new Vector3d(); boolean isParallel = false; double radius = 0.0; Vector3d eyeToCanvas = new Vector3d(); eyeToCanvas.sub (mousePosn, eyePosn); double distanceEyeToCanvas = eyeToCanvas.length(); Vector3d ptToDelta = new Vector3d(); ptToDelta.sub (mousePosn, deltaImgPlate); double distancePtToDelta = ptToDelta.length(); distancePtToDelta *= tolerance; start = new Point3d (eyePosn); // store the eye position motion.transform(mousePosn); mouseVec.sub(mousePosn, eyePosn); mouseVec.normalize();
@Override public void run() { if (DisplayCanvas.this.srcRect.contains(target)) { // reached destination if (display.getLayer() != target_layer) display.toLayer(target_layer); playHighlight(target); cancelAnimation(sf[0]); } else { setSrcRect(srcRect.x + (int)v.x, srcRect.y + (int)v.y, srcRect.width, srcRect.height); // which layer? if (start_layer != target_layer) { final int cx = srcRect.x + srcRect.width/2; final int cy = srcRect.y + srcRect.height/2; final double dist = Math.sqrt(Math.pow((cx - ox)*pixelWidth, 2) + Math.pow((cy - oy)*pixelHeight, 2) + Math.pow((display.getLayer().getZ() - start_layer.getZ()) * pixelWidth, 2)); final Vector3d gg = new Vector3d(g); gg.normalize(); gg.scale((float)dist); final Layer la = display.getLayerSet().getNearestLayer(start_layer.getZ() + gg.z/pixelWidth); if (la != display.getLayer()) { display.toLayer(la); } } display.repaintAll2(); } } }, 0, 50, TimeUnit.MILLISECONDS);
static boolean edgeIntersectPlane(Vector3d normal, Point3d pnt, Point3d start, Point3d end, Point3d iPnt){ Vector3d tempV3d = new Vector3d(); Vector3d direction = new Vector3d(); double pD, pNrmDotrDir, tr; // Compute plane D. tempV3d.set((Tuple3d) pnt); pD = normal.dot(tempV3d); direction.x = end.x - start.x; direction.y = end.y - start.y; direction.z = end.z - start.z; pNrmDotrDir = normal.dot(direction); // edge is parallel to plane. if (pNrmDotrDir== 0.0) { // System.out.println("Edge is parallel to plane."); return false; } tempV3d.set((Tuple3d) start); tr = (pD - normal.dot(tempV3d))/ pNrmDotrDir; // Edge intersects the plane behind the edge's start. // or exceed the edge's length. if ((tr < 0.0 ) || (tr > 1.0 )) { // System.out.println("Edge intersects the plane behind the start or exceed end."); return false; } iPnt.x = start.x + tr * direction.x; iPnt.y = start.y + tr * direction.y; iPnt.z = start.z + tr * direction.z; return true; }
boolean edgeIntersectSphere(BoundingSphere sphere, Point3d start, Point3d end) { double abLenSq, acLenSq, apLenSq, abDotAp, radiusSq; Vector3d ab = new Vector3d(); Vector3d ap = new Vector3d(); ab.x = end.x - start.x; ab.y = end.y - start.y; ab.z = end.z - start.z; ap.x = sphere.center.x - start.x; ap.y = sphere.center.y - start.y; ap.z = sphere.center.z - start.z; abDotAp = ab.dot(ap); if(abDotAp < 0.0) { return false; // line segment points away from sphere. } abLenSq = ab.lengthSquared(); acLenSq = abDotAp * abDotAp / abLenSq; if(acLenSq < abLenSq) { return false; // C doesn't lies between end points of edge. } radiusSq = sphere.radius * sphere.radius; apLenSq = ap.lengthSquared(); if((apLenSq - acLenSq) <= radiusSq) { return true; } return false; }
/** * 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(); }
localToVWorld.transform(p1); r = (float) p1.distance(centerInVWorld); vec.sub(centerInVWorld, eyePtInVWorld); vec.normalize(); vec.scale(-r); pickPtInVWorld.add(centerInVWorld, vec); univ.getViewPlatformTransformer().getXDir(axisPerDy, ipToVWorld); translationPerDx.set(axisPerDy); translationPerDx.scale(dX); translationPerDy.set(axisPerDx); translationPerDy.scale(dY); c.getContent().getCenter(vec); transl_inv.set(vec); vec.set(-vec.x, -vec.y, -vec.z); transl.set(vec);