public bool Intersects(GeneralLine2D line2, ref EOFC.Vector2D intersectionPt) { // If the two lines are parallel then they won't intersect if (IsParallel(line2)) { return(false); } float x, y; // Handle special case if (0.0f == A) { y = -C / B; x = (-line2.B * y - line2.C) / line2.A; intersectionPt = new EOFC.Vector2D(x, y); return(true); } float val1 = (-line2.A * B) / A + line2.B; y = ((line2.A * C / A) - line2.C) / val1; x = (-B * y - C) / A; intersectionPt = new EOFC.Vector2D(x, y); return(true); }
public bool IsParallel(GeneralLine2D line2) { // The two lines will be parallel if their normalized normal vectors are // the same or one is the negative of the other. float len1 = NormalLength; float na1 = A / len1; float nb1 = B / len1; float len2 = line2.NormalLength; float na2 = line2.A / len2; float nb2 = line2.B / len2; return((na1 == na2 && nb1 == nb2) || (na1 == -na2 && nb1 == -nb2)); }
public bool Intersects(GeneralLine2D line, ref EOFC.Vector2D outISectPt) { GeneralLine2D thisInfLine = new GeneralLine2D(m_p1, m_p2); 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); }
public GeneralLine2D(GeneralLine2D copyme) { this.A = copyme.A; this.B = copyme.B; this.C = copyme.C; }
public bool IsParallel(GeneralLine2D line2) { // The two lines will be parallel if their normalized normal vectors are // the same or one is the negative of the other. float len1 = NormalLength; float na1 = A / len1; float nb1 = B / len1; float len2 = line2.NormalLength; float na2 = line2.A / len2; float nb2 = line2.B / len2; return ((na1 == na2 && nb1 == nb2) || (na1 == -na2 && nb1 == -nb2)); }
public bool Intersects(GeneralLine2D line2, ref EOFC.Vector2D intersectionPt) { // If the two lines are parallel then they won't intersect if (IsParallel(line2)) { return false; } float x, y; // Handle special case if (0.0f == A) { y = -C / B; x = (-line2.B * y - line2.C) / line2.A; intersectionPt = new EOFC.Vector2D(x, y); return true; } float val1 = (-line2.A * B) / A + line2.B; y = ((line2.A * C / A) - line2.C) / val1; x = (-B * y - C) / A; intersectionPt = new EOFC.Vector2D(x, y); return true; }
public bool Intersects(GeneralLine2D line, ref EOFC.Vector2D outISectPt) { GeneralLine2D thisInfLine = new GeneralLine2D(m_p1, m_p2); 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; }