/// <summary> /// Calculate the position of the inner corner /// </summary> /// <param name="roadIndexA">The first road index</param> /// <param name="roadIndexB">The second road index</param> /// <param name="magnitude">The magnitude of the corner</param> /// <param name="posOut">The position of the innre corner</param> /// <returns>True if we have found a cross over</returns> public bool GetInnerCorner(int roadIndexA, int roadIndexB, float magnitude, out Vector3 posOut) { Vector3 pos = gameObject.transform.position; RoadNetworkNode rnn = Details.Roads[roadIndexA].GetComponent <RoadNetworkNode>(); Vector3 roadPointA = rnn.GetOffSetDownRoad(pos, magnitude); RoadNetworkNode rnnB = Details.Roads[roadIndexB].GetComponent <RoadNetworkNode>(); Vector3 roadPointB = rnnB.GetOffSetDownRoad(pos, magnitude); Vector3 roadPointAEnd = MathsHelper.OffSetVector( roadPointA, Details.Roads[roadIndexA].GetAngleOfRoad(pos) + (float)(Math.PI / 2), magnitude); Vector3 roadPointBEnd = MathsHelper.OffSetVector( roadPointB, Details.Roads[roadIndexB].GetAngleOfRoad(pos) + (float)(Math.PI / 2), magnitude); posOut = new Vector3(); Vector3 outB = new Vector3(); Vector3 diffA = roadPointA - roadPointAEnd; Vector3 diffB = roadPointB - roadPointBEnd; if (MathsHelper.ClosestPointsOnTwoLines(out posOut, out outB, roadPointA, diffA.normalized, roadPointB, diffB.normalized)) { return(true); } posOut = (roadPointA + roadPointB) / 2; return(false); }
/// <summary> /// Get the intersection of two points /// </summary> /// <param name="angleA">The first angle</param> /// <param name="angleB">The second angle</param> /// <param name="pointA">The first point</param> /// <param name="pointB">the second point</param> /// <param name="intersectionPoint">The intersection of the two angles</param> private static void GetPointFrom(float angleA, float angleB, Vector3 pointA, Vector3 pointB, out Vector3 intersectionPoint) { Vector3 offSetPointA = MathsHelper.OffSetVector(pointA, angleA - (float)(Math.PI / 2), 50); Vector3 offsetPointB = MathsHelper.OffSetVector(pointB, angleB - (float)(Math.PI / 2), 50); Vector3 outB = new Vector3(); Vector3 diffA = offSetPointA - pointA; Vector3 diffB = offsetPointB - pointB; MathsHelper.ClosestPointsOnTwoLines(out intersectionPoint, out outB, pointA, diffA.normalized, pointB, diffB.normalized); }
/// <summary> /// Find the overlap point of two angles /// </summary> /// <param name="angleA">Angle a</param> /// <param name="angleB">angle B</param> /// <param name="posA">Starting point A</param> /// <param name="posB">Starting point B</param> /// <param name="retPos">The overlap point of the two angles</param> /// <returns>The magnitude of the point</returns> private static float FindOverlapPoint(float angleA, float angleB, Vector3 posA, Vector3 posB, out Vector3 retPos) { Vector3 offSetPosA = MathsHelper.OffSetVector(posA, angleA - (float)(Math.PI / 2), 50); Vector3 offSetPosB = MathsHelper.OffSetVector(posB, angleB - (float)(Math.PI / 2), 50); Vector3 outB = new Vector3(); Vector3 diffA = offSetPosA - posA; Vector3 diffB = offSetPosB - posB; MathsHelper.ClosestPointsOnTwoLines(out retPos, out outB, posA, diffA.normalized, posB, diffB.normalized); Vector3 gap = retPos - posA; return(gap.magnitude); }