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; }
/** * 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(); }
static boolean edgeIntersectSphere (BoundingSphere sphere, Point3d start, Point3d end) { double abLenSq, acLenSq, apLenSq, abDotAp, radiusSq; Vector3d ab = new Vector3d(); Vector3d ap = new Vector3d(); Point3d center = new Point3d(); sphere.getCenter (center); double radius = sphere.getRadius (); ab.x = end.x - start.x; ab.y = end.y - start.y; ab.z = end.z - start.z; ap.x = center.x - start.x; ap.y = center.y - start.y; ap.z = 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 = radius * radius; apLenSq = ap.lengthSquared(); if ((apLenSq - acLenSq) <= radiusSq) return true; return false; }
return dt.lengthSquared(); double segSquared = dir.lengthSquared(); if (closest != null) closest.set(end); dt.sub(pt, end); return dt.lengthSquared(); return dt.lengthSquared();
delta1.sub(coords[index2], coords[index0]); delta2.sub(coords[index2], coords[index1]); double len0 = delta0.lengthSquared(); double len1 = delta1.lengthSquared(); double len2 = delta2.lengthSquared(); Vector3d longest = delta0; double maxLen = len0;
delta1.sub(coords[index2], coords[index0]); delta2.sub(coords[index2], coords[index1]); double len0 = delta0.lengthSquared(); double len1 = delta1.lengthSquared(); double len2 = delta2.lengthSquared(); Vector3d longest = delta0; double maxLen = len0;
nLenSq = pNrm.lengthSquared(); if ( nLenSq == 0.0) {
nLenSq = pNrm.lengthSquared(); if( nLenSq == 0.0) {