@Test public void testDistanceSquared() { Vector2 start = new Vector2(0,0); Vector2 end = new Vector2(0,1); Vector2 p0 = new Vector2(0,0); Vector2 p1 = new Vector2(1,0); assertEquals(0.0, Line.distanceSquared(start, end, p0), delta); assertEquals(1.0, Line.distanceSquared(start, end, p1), delta); }
public static double distanceSquared(Vector2 start, Vector2 end, Vector2 position) { Vector2 p = start.clone(); Vector2 v = end.subtract(start); v.normalize(); Vector2 w = position.subtract(p); double vsq = v.dot(v); double wsq = w.dot(w); double proj = w.dot(v); return wsq - proj * proj / vsq; }
Line extends Drawable { public static double distanceSquared(Vector2 start, Vector2 end, Vector2 position) { Vector2 p = start.clone(); Vector2 v = end.subtract(start); v.normalize(); Vector2 w = position.subtract(p); double vsq = v.dot(v); double wsq = w.dot(w); double proj = w.dot(v); return wsq - proj * proj / vsq; } }
Line extends Drawable { public static double distanceSquared(Vector2 start, Vector2 end, Vector2 position) { Vector2 p = start.clone(); Vector2 v = end.subtract(start); v.normalize(); Vector2 w = position.subtract(p); double vsq = v.dot(v); double wsq = w.dot(w); double proj = w.dot(v); return wsq - proj * proj / vsq; } Line(Vector2 vertices[]);  Line(Vector2 vertices[], Box2D box); }
Line extends Drawable { public static double distanceSquared(Vector2 start, Vector2 end, Vector2 position) { Vector2 p = start.clone(); Vector2 v = end.subtract(start); v.normalize(); Vector2 w = position.subtract(p); double vsq = v.dot(v); double wsq = w.dot(w); double proj = w.dot(v); return wsq - proj * proj / vsq; } Line(Vector2 vertices[]);  Line(Vector2 vertices[], Box2D box); @Override void draw(IGraphics graphics, IStyle style); @Override boolean intersect(Vector2 position, double distanceSquared); static boolean isPointInSegment(Vector2 start, Vector2 end, Vector2 position); static double distanceSquared(Vector2 start, Vector2 end, Vector2 position); @Override int getDrawableType(); }
Line extends Drawable { public static double distanceSquared(Vector2 start, Vector2 end, Vector2 position) { Vector2 p = start.clone(); Vector2 v = end.subtract(start); v.normalize(); Vector2 w = position.subtract(p); double vsq = v.dot(v); double wsq = w.dot(w); double proj = w.dot(v); return wsq - proj * proj / vsq; } Line(Vector2 vertices[]);  Line(Vector2 vertices[], Box2D box); @Override void draw(IGraphics graphics, IStyle style); @Override boolean intersect(Vector2 position, double distanceSquared); static boolean isPointInSegment(Vector2 start, Vector2 end, Vector2 position); static double distanceSquared(Vector2 start, Vector2 end, Vector2 position); @Override int getDrawableType();  }