@Test public void testNearestPoint() throws Exception { SimpleVector result = Util3D.nearestPoint( new SimpleVector[]{ new SimpleVector(0, 0, 0), new SimpleVector(5, 0, 0)}, new SimpleVector(1,1,0) ); System.out.println(result.x + ", " + result.y + ", " + result.z); }
public static SimpleVector nearestPoint(SimpleVector[] line, SimpleVector point) { SimpleVector a = new SimpleVector(line[0]); a.sub(point); SimpleVector b = new SimpleVector(line[1]); b.sub(line[0]); float top = a.calcDot(b); double t = - top / Math.pow(line[1].distance(line[0]),2.0); return new SimpleVector( line[0].x + (line[1].x - line[0].x) * t, line[0].y + (line[1].y - line[0].y) * t, line[0].z + (line[1].z - line[0].z) * t ); }
Util3D { public static SimpleVector nearestPoint(SimpleVector[] line, SimpleVector point) { SimpleVector a = new SimpleVector(line[0]); a.sub(point); SimpleVector b = new SimpleVector(line[1]); b.sub(line[0]); float top = a.calcDot(b); double t = - top / Math.pow(line[1].distance(line[0]),2.0); return new SimpleVector( line[0].x + (line[1].x - line[0].x) * t, line[0].y + (line[1].y - line[0].y) * t, line[0].z + (line[1].z - line[0].z) * t ); } }
Util3D { public static SimpleVector nearestPoint(SimpleVector[] line, SimpleVector point) { SimpleVector a = new SimpleVector(line[0]); a.sub(point); SimpleVector b = new SimpleVector(line[1]); b.sub(line[0]); float top = a.calcDot(b); double t = - top / Math.pow(line[1].distance(line[0]),2.0); return new SimpleVector( line[0].x + (line[1].x - line[0].x) * t, line[0].y + (line[1].y - line[0].y) * t, line[0].z + (line[1].z - line[0].z) * t ); }  }
Util3D { public static SimpleVector nearestPoint(SimpleVector[] line, SimpleVector point) { SimpleVector a = new SimpleVector(line[0]); a.sub(point); SimpleVector b = new SimpleVector(line[1]); b.sub(line[0]); float top = a.calcDot(b); double t = - top / Math.pow(line[1].distance(line[0]),2.0); return new SimpleVector( line[0].x + (line[1].x - line[0].x) * t, line[0].y + (line[1].y - line[0].y) * t, line[0].z + (line[1].z - line[0].z) * t ); }  static SimpleVector nearestPoint(SimpleVector[] line, SimpleVector point); static SimpleVector[] nearestLinePoints(SimpleVector[] line1, SimpleVector[] line2); static SimpleVector rayTriangleIntersects(
            SimpleVector v0, SimpleVector v1, SimpleVector v2,
            SimpleVector origin, SimpleVector dir,
            boolean isSingledSided
    ); }
Util3D { public static SimpleVector nearestPoint(SimpleVector[] line, SimpleVector point) { SimpleVector a = new SimpleVector(line[0]); a.sub(point); SimpleVector b = new SimpleVector(line[1]); b.sub(line[0]); float top = a.calcDot(b); double t = - top / Math.pow(line[1].distance(line[0]),2.0); return new SimpleVector( line[0].x + (line[1].x - line[0].x) * t, line[0].y + (line[1].y - line[0].y) * t, line[0].z + (line[1].z - line[0].z) * t ); }  static SimpleVector nearestPoint(SimpleVector[] line, SimpleVector point); static SimpleVector[] nearestLinePoints(SimpleVector[] line1, SimpleVector[] line2); static SimpleVector rayTriangleIntersects(
            SimpleVector v0, SimpleVector v1, SimpleVector v2,
            SimpleVector origin, SimpleVector dir,
            boolean isSingledSided
    );  }