public bool IsParallel(NormalizedGeneralLine2D line2) { // The two lines will be parallel if their normal vectors are the same // or one is the negative of the other. return((m_a == line2.m_a && m_b == line2.m_b) || (m_a == -line2.m_a && m_b == -line2.m_b)); }
// Checks to see if this line intersects with "line2". True is returned // if they do intersect. The "ISectPt" is optional and can be NULL, but, if // provided, it is filled with the point of intersection. // IMPORTANT: If the two lines are equal then false is returned, not true. // Do not call for degenerate lines (check with IsDegenerate). public bool Intersects(NormalizedGeneralLine2D line2, ref EOFC.Vector2D ISectPt) { // If the two lines are parallel then they won't intersect if (IsParallel(line2)) { return(false); } float x, y; // Handle special case if (m_a == 0.0f) { y = -m_c / m_b; x = (-line2.m_b * y - line2.m_c) / line2.m_a; ISectPt = new EOFC.Vector2D(x, y); return(true); } // else float val1 = (-line2.m_a * m_b) / m_a + line2.m_b; y = ((line2.m_a * m_c / m_a) - line2.m_c) / val1; x = (-m_b * y - m_c) / m_a; ISectPt = new EOFC.Vector2D(x, y); return(true); }
public bool Intersects(NormalizedGeneralLine2D line, ref EOFC.Vector2D outISectPt) { NormalizedGeneralLine2D thisInfLine = GetInfiniteLine(); EOFC.Vector2D temp = new Vector2D(); if (!thisInfLine.Intersects(line, ref temp)) { return(false); } // The two infinite lines intersect, now see if the intersection point // is on this segment if (this.IsPointOnSegment(temp)) { outISectPt = temp; return(true); } return(false); }
/// <summary> /// Gets the point on this line segment with the specified y-value. If no such point /// exists on the segment then false is returned. Note that if the segment is horizontal, /// even if it has a y-value of "y", then false is returned. /// </summary> public bool GetPointWithYValue(float y, ref EOFC.Vector2D outPt) { // If this segment is horizontal, return false. if (m_p1.Y == m_p2.Y) { return(false); } NormalizedGeneralLine2D infLine = GetInfiniteLine(); float x = infLine.GetXCoord(y); EOFC.Vector2D pt = new EOFC.Vector2D(x, y); if (IsPointOnSegment(pt)) { outPt.Set(pt); return(true); } return(false); }
/// <summary> /// Gets the point on this line segment with the specified x-value. If no such point /// exists on the segment then false is returned. Note that if the segment is vertical, /// even if it has a x-value of "x", then false is returned. /// </summary> public bool GetPointWithXValue(float x, ref EOFC.Vector2D outPt) { // If this segment is vertical, return false. if (m_p1.X == m_p2.X) { return(false); } NormalizedGeneralLine2D infLine = GetInfiniteLine(); float y = infLine.GetYCoord(x); EOFC.Vector2D pt = new EOFC.Vector2D(x, y); if (IsPointOnSegment(pt)) { outPt.Set(pt); return(true); } return(false); }
public NormalizedGeneralLine2D(NormalizedGeneralLine2D copyme) { this.m_a = copyme.m_a; this.m_b = copyme.m_b; this.m_c = copyme.m_c; }
public bool Equals(NormalizedGeneralLine2D other) { return(this.m_a == other.m_a && this.m_b == other.m_b && this.m_c == other.m_c); }