/// <summary> /// Get intersection points between a straight line and circle. /// </summary> /// <param name="line">The straight line used for the intersection.</param> /// <param name="circle">The circle used for the intersection.</param> /// <param name="intersections"></param> /// <returns></returns> public bool GetIntersection(StraightLine line, Circle circle, out Vector2[] intersections) { float g = line.Gradient; float i = line.Intercept; Vector2 c = circle.Transform.PositionGlobal; float r = circle.Radius; //Setup polynomial equation float A = 1 + g * g; float B = -2 * c.X - 2 * g * i + 2 * c.Y * g; float C = c.X * c.X + g * g + 2 * c.Y * i + c.Y * c.Y - r * r; float[] xSolutions = m_solver.Poly_2(A, B, C); intersections = new Vector2[xSolutions.Length]; if (xSolutions.Length == 0) { return(false); } for (int j = 0; j < intersections.Length; ++j) { intersections[j].X = xSolutions[j]; intersections[j].Y = g * intersections[j].X + i; } return(true); }
public Vector2 GetProjectionPoint(StraightLine screen, Vector2 projector) { Vector2 pointA = new Vector2(0, screen.GetY(0)); Vector2 AB = screen.Direction; Vector2 AX = Vector2.Subtract(projector, pointA); return(pointA + AB * GetProjectionRatio(AB, AX)); }
public bool Intersects(Circle circle, StraightLine line) { //Circle center - Projection vector Vector2 XP = GetProjectionPoint(line, circle.Transform.PositionGlobal) - circle.Transform.PositionGlobal; if (XP.Length() < circle.Radius) { return(true); } return(false); }
public bool BelongsToLine(StraightLine L2) { if (IsVertical != L2.IsVertical) { return(false); } if (IsVertical && L2.IsVertical) { return(A_Global.X == L2.GetX(0)); } return(Gradient == L2.Gradient && Intercept == L2.Intercept); }
/// <summary> /// Returns true if the lines are equal, false if they are not. /// </summary> /// <param name="lineA">First line to test.</param> /// <param name="lineB">Second Line to test.</param> /// <param name="intersection">The point of intersection.</param> /// <returns>True if the lines are equal</returns> public bool GetIntersection(StraightLine lineA, StraightLine lineB, out Vector2 intersection) { float x; float y; bool aV = lineA.IsVertical; bool bV = lineB.IsVertical; intersection = new Vector2(); //Lines are equal: intersection. if (lineA.Equals(lineB)) { return(true); } //Lines are parallel: no intersection. if (lineA.IsParallel(lineB)) { return(false); } if (aV && !bV) { x = -lineA.C / lineA.A; y = (-lineB.A * x - lineB.C) / lineB.B; intersection = new Vector2(x, y); return(true); } if (!aV && bV) { x = lineB.GetX(0); y = (-lineA.A * x - lineA.C) / lineA.B; intersection = new Vector2(x, y); return(true); } if (!aV && !bV) { x = (lineB.Intercept - lineA.Intercept) / (lineA.Gradient - lineB.Gradient); y = lineA.Gradient * x + lineA.Intercept; intersection = new Vector2(x, y); return(true); } throw new Exception("Well that wasn't supposed to happen..."); }
public bool IsEqual(StraightLine L2) { return(A == L2.A && B == L2.B && C == L2.C); }
public bool IsParallel(StraightLine L2) { return((IsVertical && L2.IsVertical) || Gradient == L2.Gradient); }
public bool Intersects(Circle circle, StraightLine line) { //Circle center - Projection vector Vector2 XP = GetProjectionPoint(line, circle.Transform.PositionGlobal) - circle.Transform.PositionGlobal; if (XP.Length() < circle.Radius) return true; return false; }
public Vector2 GetProjectionPoint(StraightLine screen, Vector2 projector) { Vector2 pointA = new Vector2(0, screen.GetY(0)); Vector2 AB = screen.Direction; Vector2 AX = Vector2.Subtract(projector, pointA); return pointA + AB * GetProjectionRatio(AB, AX); }
/// <summary> /// Returns true if the lines are equal, false if they are not. /// </summary> /// <param name="lineA">First line to test.</param> /// <param name="lineB">Second Line to test.</param> /// <param name="intersection">The point of intersection.</param> /// <returns>True if the lines are equal</returns> public bool GetIntersection(StraightLine lineA, StraightLine lineB, out Vector2 intersection) { float x; float y; bool aV = lineA.IsVertical; bool bV = lineB.IsVertical; intersection = new Vector2(); //Lines are equal: intersection. if (lineA.Equals(lineB)) return true; //Lines are parallel: no intersection. if (lineA.IsParallel(lineB)) return false; if (aV && !bV) { x = -lineA.C / lineA.A; y = (-lineB.A * x - lineB.C) / lineB.B; intersection = new Vector2(x, y); return true; } if (!aV && bV) { x = lineB.GetX(0); y = (-lineA.A * x - lineA.C) / lineA.B; intersection = new Vector2(x, y); return true; } if (!aV && !bV) { x = (lineB.Intercept - lineA.Intercept) / (lineA.Gradient - lineB.Gradient); y = lineA.Gradient * x + lineA.Intercept; intersection = new Vector2(x, y); return true; } throw new Exception("Well that wasn't supposed to happen..."); }
/// <summary> /// Get intersection points between a straight line and circle. /// </summary> /// <param name="line">The straight line used for the intersection.</param> /// <param name="circle">The circle used for the intersection.</param> /// <param name="intersections"></param> /// <returns></returns> public bool GetIntersection(StraightLine line, Circle circle, out Vector2[] intersections) { float g = line.Gradient; float i = line.Intercept; Vector2 c = circle.Transform.PositionGlobal; float r = circle.Radius; //Setup polynomial equation float A = 1 + g * g; float B = -2 * c.X - 2 * g * i + 2 * c.Y * g; float C = c.X * c.X + g * g + 2 * c.Y * i + c.Y * c.Y - r * r; float[] xSolutions = m_solver.Poly_2(A, B, C); intersections = new Vector2[xSolutions.Length]; if (xSolutions.Length == 0) return false; for(int j = 0; j < intersections.Length; ++j) { intersections[j].X = xSolutions[j]; intersections[j].Y = g * intersections[j].X + i; } return true; }
public bool IsParallel(StraightLine L2) { return (IsVertical && L2.IsVertical) || Gradient == L2.Gradient; }
public bool BelongsToLine(StraightLine L2) { if (IsVertical != L2.IsVertical) return false; if (IsVertical && L2.IsVertical) return A_Global.X == L2.GetX(0); return Gradient == L2.Gradient && Intercept == L2.Intercept; }
public bool IsEqual(StraightLine L2) { return A == L2.A && B == L2.B && C == L2.C; }