Beispiel #1
0
        public static Point Project2Vector(Point pt1, Point pt2, Point pt3)
        {
            // project a vector v1 formed by pt1-pt3 into another vector v2 formed by pt1-pt2
            Point  v1            = PA.Subtract(pt3, pt1);
            Point  v2            = PA.Subtract(pt2, pt1);
            float  scale         = (float)(PA.Dot(v1, v2) / PA.Norm(v2) / PA.Norm(v2));
            PointF projected_pt3 = PA.Add(PA.Multiply(PA.Int2Float(v2), scale), pt1);

            return(PA.Float2Int(projected_pt3));
        }
Beispiel #2
0
        public static Point Project2NormalVector(Point pt1, Point pt2, Point pt3)
        {
            /* project a vector v1 formed by pt1-pt3 into the direction of
             * the normal vector of another vector v2 formed by pt1-pt2 */

            // compute the unit normal vector of vector v2
            Point  v2          = PA.Subtract(pt2, pt1);
            float  magnitude   = (float)(PA.Norm(pt1, pt2));
            PointF unit_normal = new PointF(v2.Y / magnitude, -v2.X / magnitude);
            // project v1 into the normal vector
            Point  v1           = PA.Subtract(pt3, pt1);
            PointF projected    = PA.Multiply(unit_normal, (float)PA.Dot(v1, unit_normal));
            PointF projected_v3 = PA.Add(projected, pt1);

            return(PA.Float2Int(projected_v3));
        }