public override bool Equals(object obj) { // If the object is not of the same type then it cannot be equal if (!(obj is LineSegment2D)) { return(false); } LineSegment2D s = (LineSegment2D)obj; return(this.m_p1.Equals(s.m_p1) && this.m_p2.Equals(s.m_p2)); }
public bool IsParallel(LineSegment2D seg2) { // The two segments will be parallel if their line vectors are the same // or one is the negative of the other. EOFC.Vector2D v1 = GetVector(); EOFC.Vector2D v2 = seg2.GetVector(); v1.Normalize(); v2.Normalize(); if (v1.DotProduct(v2) == 1.0f) { return(true); } return(false); }
public bool Intersects(LineSegment2D segment2, ref EOFC.Vector2D outISectPt) { float t = 0.0f; if (!Intersects(segment2, ref t)) { return(false); } // Fill the intersection point float dx1 = m_p2.X - m_p1.X; float dy1 = m_p2.Y - m_p1.Y; outISectPt.Set(m_p1.X + t * dx1, m_p1.Y + t * dy1); return(true); }
/// <summary> /// Determines whether or not this segment intersects another. If the two segments /// do intersect, then t will be set to a value in the range [0.0f, 1.0f] indicating /// where the intersection occurs along this line, and true will be returned. If no /// intersection occurs, false is returned and t is not modified. /// </summary> /// <returns>True if the segments intersect, false otherwise.</returns> public bool Intersects(LineSegment2D segment2, ref float t) { // Build directional vectors for both lines. Negate the ones for the // second segment by flipping the subtraction order. float dx1 = m_p2.X - m_p1.X; float dy1 = m_p2.Y - m_p1.Y; float dx2 = segment2.m_p1.X - segment2.m_p2.X; float dy2 = segment2.m_p1.Y - segment2.m_p2.Y; // Calculate determinate float det = (dx1 * dy2) - (dx2 * dy1); // If the determinate is zero then there is no intersection if (0.0f == det) { return(false); } // Calculate origin differences float ox = segment2.m_p1.X - m_p1.X; float oy = segment2.m_p1.Y - m_p1.Y; // Calculate t1 and test bounds float t1 = (ox * dy2 - dx2 * oy) / det; if (t1 < 0.0f || t1 > 1.0f) { return(false); } // Calculate t2 and test bounds float t2 = (dx1 * oy - ox * dy1) / det; if (t2 < 0.0f || t2 > 1.0f) { return(false); } // Both t-values are in range, fill output t value t = t1; return(true); }
public LineSegment2D(LineSegment2D copyme) { m_p1 = copyme.m_p1; m_p2 = copyme.m_p2; m_l = (m_p2 - m_p1).Length; }
public bool IsParallel(LineSegment2D seg2) { // The two segments will be parallel if their line vectors are the same // or one is the negative of the other. EOFC.Vector2D v1 = GetVector(); EOFC.Vector2D v2 = seg2.GetVector(); v1.Normalize(); v2.Normalize(); if (v1.DotProduct(v2) == 1.0f) { return true; } return false; }
/// <summary> /// Determines whether or not this segment intersects another. If the two segments /// do intersect, then t will be set to a value in the range [0.0f, 1.0f] indicating /// where the intersection occurs along this line, and true will be returned. If no /// intersection occurs, false is returned and t is not modified. /// </summary> /// <returns>True if the segments intersect, false otherwise.</returns> public bool Intersects(LineSegment2D segment2, ref float t) { // Build directional vectors for both lines. Negate the ones for the // second segment by flipping the subtraction order. float dx1 = m_p2.X - m_p1.X; float dy1 = m_p2.Y - m_p1.Y; float dx2 = segment2.m_p1.X - segment2.m_p2.X; float dy2 = segment2.m_p1.Y - segment2.m_p2.Y; // Calculate determinate float det = (dx1 * dy2) - (dx2 * dy1); // If the determinate is zero then there is no intersection if (0.0f == det) { return false; } // Calculate origin differences float ox = segment2.m_p1.X - m_p1.X; float oy = segment2.m_p1.Y - m_p1.Y; // Calculate t1 and test bounds float t1 = (ox * dy2 - dx2 * oy) / det; if (t1 < 0.0f || t1 > 1.0f) { return false; } // Calculate t2 and test bounds float t2 = (dx1 * oy - ox * dy1) / det; if (t2 < 0.0f || t2 > 1.0f) { return false; } // Both t-values are in range, fill output t value t = t1; return true; }
public bool Intersects(LineSegment2D segment2, ref EOFC.Vector2D outISectPt) { float t = 0.0f; if (!Intersects(segment2, ref t)) { return false; } // Fill the intersection point float dx1 = m_p2.X - m_p1.X; float dy1 = m_p2.Y - m_p1.Y; outISectPt.Set(m_p1.X + t * dx1, m_p1.Y + t * dy1); return true; }