/// <summary> /// Computes the (approximate) intersection point between two line segments /// using homogeneous coordinates. /// 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. /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="q1"></param> /// <param name="q2"></param> /// <returns></returns> public static Coordinate OldIntersection(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) { var l1 = new HCoordinate(new HCoordinate(p1), new HCoordinate(p2)); var l2 = new HCoordinate(new HCoordinate(q1), new HCoordinate(q2)); var intHCoord = new HCoordinate(l1, l2); var intPt = intHCoord.Coordinate; return(intPt); }
/// <summary> /// Computes a segment intersection using homogeneous coordinates. /// Round-off error can cause the raw computation to fail, /// (usually due to the segments being approximately parallel). /// If this happens, a reasonable approximation is computed instead. /// </summary> private static Coordinate SafeHCoordinateIntersection(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) { Coordinate intPt; try { intPt = HCoordinate.Intersection(p1, p2, q1, q2); } catch (NotRepresentableException e) { intPt = CentralEndpointIntersector.GetIntersection(p1, p2, q1, q2); } return(intPt); }
/// <summary> /// Computes a segment intersection using homogeneous coordinates. /// Round-off error can cause the raw computation to fail, /// (usually due to the segments being approximately parallel). /// If this happens, a reasonable approximation is computed instead. /// </summary> private static Coordinate SafeHCoordinateIntersection(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) { Coordinate intPt; try { intPt = HCoordinate.Intersection(p1, p2, q1, q2); } catch (NotRepresentableException e) { // compute an approximate result // intPt = CentralEndpointIntersector.GetIntersection(p1, p2, q1, q2); intPt = NearestEndpoint(p1, p2, q1, q2); } return(intPt); }
/// <summary> /// /// </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; }