예제 #1
0
        /// <summary>
        /// Projects a PointF along a specified direction
        /// </summary>
        public static PointF ProjectAlong(this PointF This, PointF direction)
        {
            var normalDirection = direction.Normalize();
            var dist            = This.DotProduct(normalDirection);

            return(normalDirection.ScaledBy(dist));
        }
예제 #2
0
        private double CosBetween(PointF a, PointF b)
        {
            var dotProduct = a.DotProduct(b);
            var lenA       = a.RadiusVector();
            var lenB       = b.RadiusVector();

            return(dotProduct / (lenA * lenB));
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns>paramter of intersection equation. NaN if no intersection</returns>
        public double Intersect(Edge other)
        {
            var    t = Double.NaN;
            PointF a = Origin;
            PointF b = Destination;
            PointF c = other.Origin;
            PointF d = other.Destination;
            PointF n = new PointF(d.Substract(c).Y, c.Substract(d).X);

            var denom = n.DotProduct(b.Substract(a));

            if (denom != .0)
            {
                var num = n.DotProduct(a.Substract(c));
                t = -num / denom;
            }

            return(t);
        }
예제 #4
0
        public void PointExtensions()
        {
            var x1    = 1;
            var x2    = 2;
            var y1    = 3;
            var y2    = 4;
            var p1    = new PointF(x1, y1);
            var p2    = new PointF(x2, y2);
            var zero  = new PointF(0, 0);
            var sum12 = p1.Add(p2);

            AreEqual(new PointF(x1 + x2, y1 + y2), sum12, "Addition");
            AreEqual(p1, sum12.Subtract(p2), "Subtraction");
            AreEqual(p1.Add(p1), p1.Multiply(2), "Multiply by 2");
            Assert.AreEqual(x1 * x1 + y1 * y1, p1.LengthSquared(), 1e-5, "Length");
            Assert.IsTrue(p1.LengthSquared() > 0, "non-zero length");
            var normed = p1.Normalize();

            Assert.AreEqual(1, normed.LengthSquared(), 1e-5, "length after normalization");
            Assert.Throws <ArgumentException>(() => zero.Normalize(), "Can't normalize a zero length vector");
            Assert.AreEqual(p1.LengthSquared(), p1.DotProduct(p1), "Length and dot product with itself should match");
        }
예제 #5
0
        public static PointF ProjectAlong(this PointF This, PointF direction)
        {
            PointF @this = direction.Normalize();

            return(@this.ScaledBy(This.DotProduct(@this)));
        }