public Intersection CalculateIntersection(Slope otherSlope) { if (isVertical && otherSlope.isVertical) { return(new Intersection(b == otherSlope.b ? IntersectionType.OVERLAP : IntersectionType.NONE, Vector3.zero)); } if (isVertical || otherSlope.isVertical) { var vertical = isVertical ? this : otherSlope; var notVertical = isVertical ? otherSlope : this; return(new Intersection(IntersectionType.INTERSECT, new Vector3(vertical.b, 0, notVertical.CalculateY(vertical.b)))); } if (a == 0f && otherSlope.a == 0f) { return(new Intersection(b == otherSlope.b ? IntersectionType.OVERLAP : IntersectionType.NONE, Vector3.zero)); } if (a == 0f || otherSlope.a == 0f) { var horizontal = a == 0 ? this : otherSlope; var notHorizontal = a == 0 ? otherSlope : this; return(new Intersection(IntersectionType.INTERSECT, new Vector3(notHorizontal.CalculateIntersectionWithHorizontalLine(horizontal.b), 0, horizontal.b))); } if (a == otherSlope.a && b == otherSlope.b) { return(new Intersection(IntersectionType.OVERLAP, Vector3.zero)); } if (a == otherSlope.a && b != otherSlope.b) { return(new Intersection(IntersectionType.NONE, Vector3.zero)); } var x = CalculateXIntersection(otherSlope); var z = CalculateY(x); return(new Intersection(IntersectionType.INTERSECT, new Vector3(x, 0, z))); }
public float CalculateXIntersection(Slope otherSlope) { return((otherSlope.b - b) / (a - otherSlope.a)); }