示例#1
0
    /// <summary>
    /// 多边形边
    /// </summary>
    /// <param name="_vertexA">顶点A</param>
    /// <param name="_vertexB">顶点B</param>
    public PolygonEdge2D(PolygonPoint2D _vertexA, PolygonPoint2D _vertexB)
    {
        vertexA = _vertexA;
        vertexB = _vertexB;
        List <int> sort = new List <int>()
        {
            _vertexA.index, _vertexB.index
        };

        sort.Sort();
        StringBuilder sb = new StringBuilder();

        foreach (int k in sort)
        {
            sb.Append(k);
        }
        key = sb.ToString().UniqueHashCode();
    }
    /// <summary>
    /// 多边形三角形
    /// </summary>
    /// <param name="_vertexA">顶点A</param>
    /// <param name="_vertexB">顶点B</param>
    /// <param name="_vertexC">顶点C</param>
    public PolygonTriangle2D(PolygonPoint2D _vertexA, PolygonPoint2D _vertexB, PolygonPoint2D _vertexC)
    {
        //Vector3 ab = (_vertexB.position - _vertexA.position).normalized;
        //Vector3 ac = (_vertexC.position - _vertexA.position).normalized;
        //Vector3 vc = Vector3.Cross(ab, ac);
        //if (vc.z > 0)
        //{
        //    //逆时针三角形,B,C点交换
        //    PolygonPoint2D p = _vertexC;
        //    _vertexC = _vertexB;
        //    _vertexB = p;
        //}
        vertexs = new PolygonPoint2D[3] {
            _vertexA, _vertexB, _vertexC
        };
        edges = new PolygonEdge2D[3] {
            new PolygonEdge2D(_vertexA, _vertexB), new PolygonEdge2D(_vertexB, _vertexC), new PolygonEdge2D(_vertexC, _vertexA)
        };
        circumCircleCenter = Geometry2DUtility.TriangleCircumCircle(_vertexA.position, _vertexB.position, _vertexC.position);
        circumCircleRadius = Vector3.Distance(circumCircleCenter, _vertexA.position);

        key = (_vertexA.index.ToString() + _vertexB.index.ToString() + _vertexC.ToString()).UniqueHashCode();
    }