Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        // tri
        Debug.DrawLine(p0.position, p1.position, Color.red);
        Debug.DrawLine(p0.position, p2.position, Color.red);
        Debug.DrawLine(p1.position, p2.position, Color.red);


        // edge
        Debug.DrawLine(e0.position, e1.position, Color.blue);

        // algorithm
        intersect = TriTriOverlap.TriEdgeIntersect(p0.position, p1.position, p2.position, e0.position, e1.position, out intersectPoint);
    }
    public bool AssessEdgeIntersection(EdgeController edge)
    {
        foreach (var tri in currentTriangles)
        {
            Vector3 centroid = (
                tri[0].transform.position +
                tri[1].transform.position +
                tri[2].transform.position) / 3f;

            // shift all points by an epsilon inwards, to make sure points aren't erronously said to
            // overlap due to floating point errors.

            Vector3 pos1 = Vector3.MoveTowards(
                tri[0].transform.position, centroid, .01f
                );

            Vector3 pos2 = Vector3.MoveTowards(
                tri[1].transform.position, centroid, .01f
                );

            Vector3 pos3 = Vector3.MoveTowards(
                tri[2].transform.position, centroid, .01f
                );

            Vector3?intersectionPoint = null;
            bool    intersects        = TriTriOverlap.TriEdgeIntersect(
                pos1,
                pos2,
                pos3,
                edge.startNode.transform.position,
                edge.endNode.transform.position,
                out intersectionPoint
                );

            if (intersects)
            {
                return(true);
            }
        }
        return(false);
    }