} else { diff.scaleAdd (-t, raydir, diff); // diff = diff - t*ray.m; if (rayint != null) rayint.scaleAdd (t, raydir, rayorig); if (param != null) { param[0] = t; }
/** * 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(); }
diff.scaleAdd (-t, segdir, diff); //diff = diff - t*seg.m; if (segint != null) segint.scaleAdd (t, segdir, segstart); if (param != null) { param[0] = t; }
dt.scaleAdd(proj / segSquared, dir, start); if (closest != null) closest.set(dt);