Ejemplo n.º 1
0
        /// <summary>
        /// Find the intersection between two edges.
        /// </summary>
        /// <param name="other">other edge</param>
        /// <returns>intersection point</returns>
        public Vertex findIntersection(Edge other)
        {
            double[] vertices = Mathy.findIntersection(
                p.vector.x, p.vector.y,
                q.vector.x, q.vector.y,
                other.p.vector.x, other.p.vector.y,
                other.q.vector.x, other.q.vector.y
                );

            if (vertices != null)
            {
                return(new Vertex(vertices[0], vertices[1]));
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds area of a polygon that is not self-intersecting.
        /// Requires vertices to be ordered counter-clockwise. Calling this
        /// function on self-intersecting polygons will result in unexpected
        /// answers.
        /// </summary>
        /// <returns>Area of the polygon.</returns>
        public double getArea()
        {
            if (sides.Count < 3)
            {
                return(0);
            }
            double area = 0;

            for (int i = 0; i < vertices.Count; ++i)
            {
                if (i == vertices.Count - 1)    // Last one "wraps around"
                {
                    area += Mathy.determinant2(vertices[i], vertices[0]);
                }
                else
                {
                    area += Mathy.determinant2(vertices[i], vertices[i + 1]);
                }
            }

            return(Math.Abs(area * 0.5));
        }
Ejemplo n.º 3
0
        /* End comparator functions */

        /// <summary>
        /// Euclidean distance between two Cartesian coordiates
        /// </summary>
        /// <param name="other">distant vertex</param>
        /// <returns>distance</returns>
        public double getDistanceTo(Vertex other)
        {
            return(Mathy.getDistanceBetween(x, y, other.x, other.y));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Get the angle of rotation from this vertex to another
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public float getAngleOfRotationTo(Vertex other)
 {
     return((float)Mathy.getAngleOfRotation(x, y, other.x, other.y));
 }