public class LineSeg2D { Vector2D p1; Vector2D p2; boolean killMe; LineSeg2D() { p1 = new Vector2D(); p2 = new Vector2D(); killMe = false; } LineSeg2D(Vector2D v1, Vector2D v2) { p1 = new Vector2D(); p2 = new Vector2D(); p1.Set(v1); p2.Set(v2); killMe = false; } LineSeg2D(float x1, float y1, float x2, float y2) { p1 = new Vector2D(); p2 = new Vector2D(); p1.Set(x1, y1); p2.Set(x2, y2); killMe = false; } public float Length() { return ((float)(p1.Minus(p2)).magnitude()); } public Vector2D CenterPoint() { return new Vector2D((p1.x+p2.x)*.5f,(p1.y+p2.y)*.5f); } public void SetP1(float x, float y) { p1.x = x; p1.y = y; } public void SetP1(Vector2D v) { p1.Set(v); } public void SetP2(float x, float y) { p2.x = x; p2.y = y; } public void SetP2(Vector2D v) { p2.Set(v); } public Vector2D Norm() { Vector2D v = RayVector(); v.Rotate90CW(); return (v); } public Vector2D UnitNorm() { Vector2D v = RayVector(); v.Rotate90CW(); return (v.retNormalize()); } public Vector2D RayVector() { return p2.Minus(p1); } //Returns 'D' - the distance from the origin in the plane equation public float GetD() { return -((UnitNorm()).Dot(p1)); } public float LengthSquared() { float dx = p1.x - p2.x; float dy = p1.y - p2.y; return (dx*dx + dy*dy); } public LineSeg2D retReverse() { return new LineSeg2D(p2,p1); } }