public Matrix4x4 GetTransform(float distance) { if (distance > arc1.Length) { distance -= arc1.Length; return(arc2.GetTransform(distance)); } return(arc1.GetTransform(distance)); }
private static bool intersectsDiscrete(ILoftPath a, float widthA, ILoftPath b, float widthB, IntersectionMode mode, out float offsetA, out float offsetB) { widthA /= 2; widthB /= 2; // TODO: optimize! var lenA = a.Length; var lenB = b.Length; var countA = Mathf.CeilToInt(lenA) / 4; var countB = Mathf.CeilToInt(lenB) / 4; var dA = lenA / countA; var dB = lenB / countB; var lTA = a.GetTransform(0); for (int iA = 1; iA <= countA; iA++) { var oA = iA * lenA / countA; var tA = a.GetTransform(oA); var aLP = t2d(lTA.GetColumn(3)); var aLT = t2d(lTA.GetColumn(0)) * widthA; var aCP = t2d(tA.GetColumn(3)); var aCT = t2d(tA.GetColumn(0)) * widthA; var aD = aCP - aLP; lTA = tA; var lTB = b.GetTransform(0); for (int iB = 1; iB <= countB; iB++) { var oB = iB * lenB / countB; var tB = b.GetTransform(oB); var bLP = t2d(lTB.GetColumn(3)); var bLT = t2d(lTB.GetColumn(0)) * widthB; var bCP = t2d(tB.GetColumn(3)); var bCT = t2d(tB.GetColumn(0)) * widthB; var bD = bCP - bLP; lTB = tB; //Debug.DrawLine(t3d(bLP), t3d(bCP), Color.white); //Debug.DrawLine(t3d(aLP), t3d(aCP), Color.white); //Debug.DrawLine(t3d(bLP + bLT * signB), t3d(bCP + bCT * signB), Color.cyan); //Debug.DrawLine(t3d(aLP + aLT * signA), t3d(aCP + aCT * signA), Color.cyan); //Debug.DrawLine(t3d(bLP - bLT * signB), t3d(bCP - bCT * signB), Color.magenta); //Debug.DrawLine(t3d(aLP - aLT * signA), t3d(aCP - aCT * signA), Color.magenta); var aS1 = aLP + aLT; var bS1 = bLP + bLT; var aS2 = aLP - aLT; var bS2 = bLP - bLT; var aD1 = (aCP + aCT) - aS1; var bD1 = (bCP + bCT) - bS1; var aD2 = (aCP - aCT) - aS2; var bD2 = (bCP - bCT) - bS2; //Debug.DrawLine(t3d(aS1, iA), t3d(aS1 + aD1, iA), Color.cyan); //Debug.DrawLine(t3d(bS1, iA), t3d(bS1 + bD1, iA), Color.cyan); //Debug.DrawLine(t3d(aS2, iA), t3d(aS2 + aD2, iA), Color.magenta); //Debug.DrawLine(t3d(bS2, iA), t3d(bS2 + bD2, iA), Color.magenta); if (mode == IntersectionMode.Edge) { if (intersectsDiscreteSegment(0, a, b, out offsetA, out offsetB, dA, dB, oA, oB, aS1, aD1, bS1, bD1)) { return(true); } if (intersectsDiscreteSegment(1, a, b, out offsetA, out offsetB, dA, dB, oA, oB, aS2, aD2, bS2, bD2)) { return(true); } if (intersectsDiscreteSegment(2, a, b, out offsetA, out offsetB, dA, dB, oA, oB, aS1, aD1, bS2, bD2)) { return(true); } if (intersectsDiscreteSegment(3, a, b, out offsetA, out offsetB, dA, dB, oA, oB, aS2, aD2, bS1, bD1)) { return(true); } } else { if (intersectsDiscreteSegment(0, a, b, out offsetA, out offsetB, dA, dB, oA, oB, aLP, bLP, aCP - aLP, bCP - bLP)) { return(true); } } } } offsetA = offsetB = float.NaN; return(false); }
public static Matrix4x4 GetTransform(this ILoftPath loft, float distance, Matrix4x4 baseTransform) { return(baseTransform * loft.GetTransform(distance)); }
private static bool test(int a, int b, ILoftPath pathA, float startA, float scaleA, float widthA, ILoftPath pathB, float startB, float scaleB, float widthB, out float offsetA, out float offsetB) { var sA = startA + (a - 1) * scaleA; var eA = startA + (a) * scaleA; var sB = startB + (b - 1) * scaleB; var eB = startB + (b) * scaleB; var sAM = pathA.GetTransform(sA); var eAM = pathA.GetTransform(eA); var sBM = pathB.GetTransform(sB); var eBM = pathB.GetTransform(eB); var sAP = getPoint(sAM, 3); var eAP = getPoint(eAM, 3); var sAT = getPoint(sAM, 0); var eAT = getPoint(eAM, 0); var sBP = getPoint(sBM, 3); var eBP = getPoint(eBM, 3); var sBT = getPoint(sBM, 0); var eBT = getPoint(eBM, 0); var cA = (sAP + eAP) / 2; var cB = (sBP + eBP) / 2; var tA = cA - cB; var tB = -tA; var mA = Mathf.Sign(Vector2.Dot(tA, sAT)) * widthA; var mB = Mathf.Sign(Vector2.Dot(tB, sBT)) * widthB; eAP -= eAT * mA; sAP -= sAT * mA; eBP -= eBT * mB; sBP -= sBT * mB; var dA = eAP - sAP; var dB = eBP - sBP; VectorMath2D.IntersectsLineLine(sAP, dA, sBP, dB, out offsetA, out offsetB); //Debug.DrawLine(t3d(sAP), t3d(eAP), Color.magenta); //Debug.DrawLine(t3d(sBP), t3d(eBP), Color.cyan); //Debug.DrawLine(t3d(cA + sAT), t3d(cA - sAT), Color.red); //Debug.DrawLine(t3d(cB + sBT), t3d(cB - sBT), Color.blue); //Debug.DrawLine(t3d(cB), t3d(cB), Color.yellow); if (offsetA >= 0 && offsetB >= 0 && offsetA <= 1 && offsetB <= 1) { offsetA = sA + offsetA * scaleA; offsetB = sB + offsetB * scaleB; //var pA = pathA.GetTransformedPoint(offsetA, Vector3.zero); //var pB = pathB.GetTransformedPoint(offsetB, Vector3.zero); //Debug.DrawLine(pB, t3d(sAP), Color.red); //Debug.DrawLine(pA, t3d(sBP), Color.blue); return(true); } offsetA = offsetB = float.NaN; return(false); }
public static Vector3 GetTransformedPoint(this ILoftPath loft, float distance, Vector3 input) { var m = loft.GetTransform(distance); return(m.MultiplyPoint3x4(input)); }