示例#1
0
        /// <summary>
        /// The offset interpolate.
        /// </summary>
        /// <param name="Value1">The Value1.</param>
        /// <param name="Value2">The Value2.</param>
        /// <param name="Offset">The Offset.</param>
        /// <param name="Weight">The Weight.</param>
        /// <returns>The <see cref="Point2D"/>.</returns>
        public static Point2D OffsetInterpolate(Point2D Value1, Point2D Value2, double Offset, double Weight)
        {
            var UnitVectorAB    = new Vector2D(Value1, Value2);
            var PerpendicularAB = new Vector2D(PerpendicularClockwiseVectorTests.PerpendicularClockwise(UnitVectorAB.I, UnitVectorAB.J)) * 0.5d * Offset;

            return(new Point2D(InterpolateLinear2DTests.LinearInterpolate2D(Weight, Value1.X, Value1.Y, Value2.X, Value2.Y)) * (Size2D)PerpendicularAB);
        }
示例#2
0
        /// <summary>
        /// Calculate the geometry of points offset at a specified distance. aka Double Line.
        /// </summary>
        /// <param name="pointA">First reference point.</param>
        /// <param name="pointB">First inclusive point.</param>
        /// <param name="pointC">Second inclusive point.</param>
        /// <param name="pointD">Second reference point.</param>
        /// <param name="offsetDistance">Offset Distance</param>
        /// <returns></returns>
        /// <acknowledgment>
        /// Suppose you have 4 points; A, B C, and D. With Lines AB, BC, and CD.<BR/>
        ///<BR/>
        ///                 B1         BC1       C1<BR/>
        ///                   |\¯B¯¯¯¯¯BC¯¯¯C¯¯¯/|<BR/>
        ///                   | \--------------/ |<BR/>
        ///                   | |\____________/| |<BR/>
        ///                   | | |B2  BC2 C2| | |<BR/>
        ///                 AB| | |          | | |CD<BR/>
        ///                AB1| | |AB2    CD2| | |CD1<BR/>
        ///                   | | |          | | |<BR/>
        ///                   | | |          | | |<BR/>
        ///               A1  A  A2      D2  D  D1<BR/>
        ///
        /// </acknowledgment>
        public static Point2D[] CenteredOffsetLinePoints(Point2D pointA, Point2D pointB, Point2D pointC, Point2D pointD, double offsetDistance)
        {
            // To get the vectors of the angles at each corner B and C, Normalize the Unit Delta Vectors along AB, BC, and CD.
            var UnitVectorAB = pointB - pointA;

            UnitVectorAB = new Vector2D(Normalize2DVectorTests.Normalize(UnitVectorAB.I, UnitVectorAB.J));
            var UnitVectorBC = pointC - pointB;

            UnitVectorBC = new Vector2D(Normalize2DVectorTests.Normalize(UnitVectorBC.I, UnitVectorBC.J));
            var UnitVectorCD = pointD - pointC;

            UnitVectorCD = new Vector2D(Normalize2DVectorTests.Normalize(UnitVectorCD.I, UnitVectorCD.J));


            //  Find the Perpendicular of the outside vectors
            var PerpendicularAB = new Vector2D(PerpendicularClockwiseVectorTests.PerpendicularClockwise(UnitVectorAB.I, UnitVectorAB.J));
            var PerpendicularCD = new Vector2D(PerpendicularClockwiseVectorTests.PerpendicularClockwise(UnitVectorCD.I, UnitVectorCD.J));

            //  Normalized Vectors pointing out from B and C.
            var OutUnitVectorB = UnitVectorAB - UnitVectorBC;

            OutUnitVectorB = new Vector2D(Normalize2DVectorTests.Normalize(OutUnitVectorB.I, OutUnitVectorB.J));
            var OutUnitVectorC = UnitVectorCD - UnitVectorBC;

            OutUnitVectorC = new Vector2D(Normalize2DVectorTests.Normalize(OutUnitVectorC.I, OutUnitVectorC.J));

            //  The distance out from B is the radius / Cos(theta) where theta is the angle
            //  from the perpendicular of BC of the UnitVector. The cosine can also be
            //  calculated by doing the dot product of  Unit(Perpendicular(AB)) and
            //  UnitVector.
            var BPointScale = DotProduct2Vector2DTests.DotProduct2D(PerpendicularAB.I, PerpendicularAB.J, OutUnitVectorB.I, OutUnitVectorB.J) * offsetDistance;
            var CPointScale = DotProduct2Vector2DTests.DotProduct2D(PerpendicularCD.I, PerpendicularCD.J, OutUnitVectorC.I, OutUnitVectorC.J) * offsetDistance;

            OutUnitVectorB *= CPointScale;
            OutUnitVectorC *= BPointScale;

            // Corners of the parallelogram to draw
            var Out = new Point2D[] {
                pointC + OutUnitVectorC,
                pointB + OutUnitVectorB,
                pointB - OutUnitVectorB,
                pointC - OutUnitVectorC,
                pointC + OutUnitVectorC
            };

            return(Out);
        }