/// <summary> /// Calculates the intersection point of two lines. /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="q1"></param> /// <param name="q2"></param> /// <returns></returns> private Coordinate Intersection(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) { Coordinate n1 = new Coordinate(p1); Coordinate n2 = new Coordinate(p2); Coordinate n3 = new Coordinate(q1); Coordinate n4 = new Coordinate(q2); Coordinate normPt = new Coordinate(); Normalize(n1, n2, n3, n4, normPt); Coordinate intPt = null; try { intPt = HCoordinate.Intersection(n1, n2, n3, n4); } catch (NotRepresentableException e) { throw new NotRepresentableException("Coordinate for intersection is not calculable", e); } intPt.X += normPt.X; intPt.Y += normPt.Y; if (_makePrecise) { intPt.MakePrecise(); } return(intPt); }
/// <summary> /// Computes the (approximate) intersection point between two line segments /// using homogeneous coordinates. /// </summary> /// <remarks>Note that this algorithm is /// not numerically stable; i.e. it can produce intersection points which /// lie outside the envelope of the line segments themselves. In order /// to increase the precision of the calculation input points should be normalized /// before passing them to this routine. /// </remarks> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="q1"></param> /// <param name="q2"></param> /// <returns></returns> public static Coordinate Intersection( Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) { HCoordinate l1 = new HCoordinate(new HCoordinate(p1), new HCoordinate(p2)); HCoordinate l2 = new HCoordinate(new HCoordinate(q1), new HCoordinate(q2)); HCoordinate intHCoord = new HCoordinate(l1, l2); Coordinate intPt = intHCoord.GetCoordinate(); return(intPt); }
/// <summary> /// Constructs HCoordinate based on p1 and p2. /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> public HCoordinate(HCoordinate p1, HCoordinate p2) { _x = p1.Y * p2.W - p2.Y * p1.W; _y = p2.X * p1.W - p1.X * p2.W; _w = p1.X * p2.Y - p2.X * p1.Y; }