public bool intersectWith(Line2D l, Vector2D o) { bool found = false; float a1, a2, b1, b2; // calculate slopes, deal with infinity if (End.X - Start.X == 0) b1 = (float)1e+10; else b1 = (End.Y - Start.Y) / (End.X - Start.X); if (l.End.X - l.Start.X == 0) b2 = (float)1e+10; else b2 = (l.End.Y - l.Start.Y) / (l.End.X - l.Start.X); // calculate position a1 = Start.Y - b1 * Start.X; a2 = l.Start.Y - b2 * l.Start.X; o.X = -(a1 - a2) / (b1 - b2); o.Y = a1 + b1 * o.X; // did the lines cross? if ((Start.X - o.X) * (o.X - End.X) >= -ROUNDING_ERROR_32 && (l.Start.X - o.X) * (o.X - l.End.X) >= -ROUNDING_ERROR_32 && (Start.Y - o.Y) * (o.Y - End.Y) >= -ROUNDING_ERROR_32 && (l.Start.Y - o.Y) * (o.Y - l.End.Y) >= -ROUNDING_ERROR_32) { found = true; } return found; }
public double GetAngleWith(Line2D l) { Vector2D vect = Vector; Vector2D vect2 = l.Vector; return vect.GetAngleWith(vect2); }
public static Line2D From(float xMin, float yMin, float xMax, float yMax) { Line2D line = new Line2D(); line.Start = new Vector2D(); line.End = new Vector2D(); line.Start.Set(xMin, yMin); line.End.Set(xMax, yMax); return line; }