コード例 #1
0
        /// <summary>
        /// Return true if the vertex is reflex - that is if the angle between
        /// its in-edge and out-edge is greater than Pi (180°) on the side of interest
        /// </summary>
        /// <param name="vertex">The vertex to be tested for reflexivity</param>
        /// <returns>true if the vertex is reflex. false if the vertext is convex or straight.</returns>
        private static bool IsReflex(Vertex vertex)
        {
            Edge inEdge  = vertex.inEdge;
            Edge outEdge = vertex.outEdge;
            // TODO: Refactor to use Edge.Vector
            Vector2D v1  = inEdge.target.Position - inEdge.source.Position;
            Vector2D v2  = outEdge.target.Position - outEdge.source.Position;
            double   det = v1.Determinant(v2);

            return(det > 0.0);
        }
コード例 #2
0
ファイル: VectorGeometry.cs プロジェクト: vcer007/geodyssey
        /// <summary>
        /// Determine the direction bisecting the clockwise angle between vectors
        /// a and b when vectors a and b are placed tip-to-tail.
        /// </summary>
        /// <param name="a">First vector</param>
        /// <param name="b">Second vector</param>
        /// <returns></returns>
        public static Direction2D Bisector(ref Vector2D a, ref Vector2D b)
        {
            Vector2D aUnit = a.Unit;
            Vector2D bUnit = b.Unit;
            int      sign  = Math.Sign(a.Determinant(b));

            if (sign < 0)
            {
                Direction2D bisector = new Direction2D(bUnit - aUnit);
                return(bisector);
            }
            if (sign > 0)
            {
                Direction2D bisector = new Direction2D(aUnit - bUnit);
                return(bisector);
            }
            // sign == 0 - vectors are parallel
            if (Math.Sign(a.DeltaX) == Math.Sign(b.DeltaX) &&
                Math.Sign(a.DeltaY) == Math.Sign(b.DeltaY))
            {
                return(new Direction2D(PerpendicularRight(a)));
            }
            return(new Direction2D(b));
        }