コード例 #1
0
    void Update()
    {
        Plane planeA = new Plane(PlaneA.forward, PlaneA.position);
        Plane planeB = new Plane(PlaneB.forward, PlaneB.position);
        PlanePlaneIntersection intersectionResult = GetIntersectionBetweenTwoPlanes(planeA, planeB);

        if (intersectionResult.PlanesIntersect)
        {
            Debug.DrawRay(intersectionResult.PointOnLine, intersectionResult.NormalOfLine, Color.red);
        }
    }
コード例 #2
0
    void Update()
    {
        MyPlane planeA = PlaneFromThreePoints(TriPointA1.position, TriPointA2.position, TriPointA3.position);
        MyPlane planeB = PlaneFromThreePoints(TriPointB1.position, TriPointB2.position, TriPointB3.position);
        PlanePlaneIntersection intersectionResult = GetIntersectionBetweenTwoPlanes(planeA, planeB);

        if (intersectionResult.PlanesIntersect)
        {
            Debug.DrawRay(intersectionResult.PointOnLine, intersectionResult.NormalOfLine, Color.red);
        }
    }
コード例 #3
0
    private Vector3?GetInterWithNextCircle(int i)
    {
        if (planeInter[i].type != PlaneSphereIntersection.eType.Circle)
        {
            return(null);
        }

        int nextIndex = (i + 1) % 4;

        if (planeInter[nextIndex].type != PlaneSphereIntersection.eType.Circle)
        {
            return(null);
        }

        PlanePlaneIntersection ppI = new PlanePlaneIntersection(plane[i], plane[nextIndex]);
        LineSphereIntersection lsI = new LineSphereIntersection(ppI.O, ppI.D, center, radius);

        if (lsI.type == LineSphereIntersection.eType.None)
        {
            return(null);
        }

        if (lsI.type == LineSphereIntersection.eType.OnePoint)
        {
            return(lsI.I0);
        }
        Vector3 OI0    = (lsI.I0 - camPosition);
        Vector3 OI1    = (lsI.I1 - camPosition);
        Vector3 camDir = camTransform.forward;

        if (Vector3.Dot(camDir, OI0) < 0)
        {
            if (Vector3.Dot(camDir, OI1) < 0)
            {
                return(null);
            }
            return(lsI.I0);
        }
        else
        {
            if (Vector3.Dot(camDir, OI1) < 0)
            {
                return(lsI.I0);
            }
        }

        float d0 = OI0.sqrMagnitude;
        float d1 = OI1.sqrMagnitude;

        return(d0 > d1 ? lsI.I1 : lsI.I0);
    }
コード例 #4
0
    void Update()
    {
        MyPlane planeA = PlaneFromThreePoints(TriPointA1.position, TriPointA2.position, TriPointA3.position);
        MyPlane planeB = PlaneFromThreePoints(TriPointB1.position, TriPointB2.position, TriPointB3.position);
        PlanePlaneIntersection intersectionResult = GetIntersectionBetweenTwoPlanes(planeA, planeB);

        if (intersectionResult.PlanesIntersect)
        {
            Vector3 theThing = DoTheThing(planeB, TriPointB1.position, TriPointB2.position, intersectionResult);
            Debug.DrawRay(theThing, intersectionResult.NormalOfLine, Color.red);
            Debug.DrawRay(theThing, -intersectionResult.NormalOfLine, Color.green);
        }

        Vector3 test = ProjectPointOnPlane(PlaneTestProjector.position, planeB.normal, planeB.distance);

        //Debug.DrawRay(test, intersectionResult.NormalOfLine, Color.red);
        //Debug.DrawRay(test, -intersectionResult.NormalOfLine, Color.green);
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        Transform p1t = inPlane1.transform;
        Transform p2t = inPlane2.transform;

        plane1 = new Plane(p1t.position, p1t.position + p1t.right, p1t.position + p1t.up);
        plane2 = new Plane(p2t.position, p2t.position + p2t.right, p2t.position + p2t.up);

        Debug.DrawRay(plane1.normal * plane1.distance, plane1.normal, Color.green);
        Debug.DrawRay(plane2.normal * plane2.distance, plane2.normal, Color.blue);

        var intersection = PlanePlaneIntersection.PlanePlaneIntersect(plane1, plane2);

        if (intersection.Intersect)
        {
            if (intersection.IsLine)
            {
                var start = intersection.Line.Origin;
                Debug.DrawLine(start - intersection.Line.Direction * 100, start + intersection.Line.Direction * 100, Color.magenta);
            }
        }

        DebugDrawPlanes();
    }
コード例 #6
0
    private static Vector3 DoTheThing(MyPlane trianglePlane, Vector3 triEdgeStart, Vector3 triEdgeEnd, PlanePlaneIntersection lineOfIntersection)
    {
        Vector3 u;
        Vector3 uBasis = new Vector3(trianglePlane.normal.y, -trianglePlane.normal.x, 0);

        if (uBasis.sqrMagnitude < float.Epsilon)
        {
            u = new Vector3(0, 0, 1);
        }
        else
        {
            u = uBasis.normalized;
        }
        Vector3 v = Vector3.Cross(trianglePlane.normal, u);

        Vector2 flatEdgeStart      = FlattenPoint(u, v, triEdgeStart);
        Vector2 flatEdgeEnd        = FlattenPoint(u, v, triEdgeEnd);
        Vector2 flatIntersectStart = FlattenPoint(u, v, lineOfIntersection.PointOnLine);
        Vector2 flatIntersectEnd   = FlattenPoint(u, v, lineOfIntersection.PointOnLine + lineOfIntersection.NormalOfLine);
        Vector2 flatRet            = Vector2.zero;

        bool intersects = LineLineIntersect(flatEdgeStart, flatEdgeEnd, flatIntersectStart, flatIntersectEnd, out flatRet);


        Debug.DrawLine(flatEdgeStart, flatEdgeEnd, Color.blue);
        Debug.DrawLine(flatIntersectStart, flatIntersectEnd, Color.white);
        Debug.DrawLine(flatRet, flatRet + Vector2.up, Color.yellow);

        Vector3 ret = ProjectPointOnPlane(flatRet, trianglePlane.normal, trianglePlane.distance);

        return(ret);
    }
コード例 #7
0
    private bool GetPointsForCircleIntersection(int index, out Vector3 start, out Vector3 end)
    {
        PlanePlaneIntersection ppI = new PlanePlaneIntersection(plane[index], backPlane);
        LineSphereIntersection lsI = new LineSphereIntersection(ppI.O, ppI.D, center, radius);

        if (lsI.type == LineSphereIntersection.eType.None)
        {
            Debug.LogError("This should not be possible");
            start = end = Vector3.zero;
            return(false);
        }

        if (lsI.type == LineSphereIntersection.eType.OnePoint)
        {
            // just grazing the surface, don't add a segment for that
            start = end = Vector3.zero;
            return(false);
        }

        bool b0 = IsInFront(lsI.I0);
        bool b1 = IsInFront(lsI.I1);

        if (!b0 && !b1)
        {
            start = end = Vector3.zero;
            return(false);
        }
        int previousIndex = (index + 3) % 4;

        if (!b0)
        {
            if (circleInter[previousIndex].HasValue)
            {
                start = circleInter[previousIndex].Value;
                end   = circleInter[index].HasValue ? circleInter[index].Value : lsI.I1;
                return(true);
            }
            if (circleInter[index].HasValue)
            {
                start = lsI.I1;
                end   = circleInter[index].Value;
                return(true);
            }
            start = end = Vector3.zero;
            return(false);
        }
        if (!b1)
        {
            if (circleInter[previousIndex].HasValue)
            {
                start = circleInter[previousIndex].Value;
                end   = circleInter[index].HasValue ? circleInter[index].Value : lsI.I0;
                return(true);
            }
            if (circleInter[index].HasValue)
            {
                start = lsI.I0;
                end   = circleInter[index].Value;
                return(true);
            }
            start = end = Vector3.zero;
            return(false);
        }



        if (plane[previousIndex].Distance(lsI.I0) < plane[previousIndex].Distance(lsI.I1))
        {
            start = circleInter[previousIndex].HasValue ? circleInter[previousIndex].Value : lsI.I0;
            end   = circleInter[index].HasValue ? circleInter[index].Value : lsI.I1;
        }
        else
        {
            start = circleInter[previousIndex].HasValue ? circleInter[previousIndex].Value : lsI.I1;
            end   = circleInter[index].HasValue ? circleInter[index].Value : lsI.I0;
        }
        return(true);
    }