AngleToClock() public static method

Returns the clockwise angle between two vectors (between 0 and 2*pi) NOTE: A unique clockwise angle really only makes sense onces you've picked a plane normal direction. So as coded, this function is really only intended to be used with 2D vector inputs.
public static AngleToClock ( Vector3D v1, Vector3D v2 ) : double
v1 Vector3D
v2 Vector3D
return double
Exemplo n.º 1
0
        /// <summary>
        /// Checks to see if two points are ordered on this segment, that is:
        /// P1 -> test1 -> test2 -> P2 returns true.
        /// P1 -> test2 -> test1 -> P2 returns false;
        /// Also returns false if test1 or test2 are equal, not on the segment, or are an endpoint.
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        public bool Ordered(Vector3D test1, Vector3D test2)
        {
            if (test1.Compare(test2))
            {
                Debug.Assert(false);
                return(false);
            }
            if (!IsPointOn(test1) || !IsPointOn(test2))
            {
                Debug.Assert(false);
                return(false);
            }
            if (test1.Compare(P1) || test1.Compare(P2) ||
                test2.Compare(P1) || test2.Compare(P2))
            {
                return(false);
            }

            if (SegmentType.Arc == Type)
            {
                Vector3D t1 = P1 - Center;
                Vector3D t2 = test1 - Center;
                Vector3D t3 = test2 - Center;
                double   a1 = Clockwise ? Euclidean2D.AngleToClock(t1, t2) : Euclidean2D.AngleToCounterClock(t1, t2);
                double   a2 = Clockwise ? Euclidean2D.AngleToClock(t1, t3) : Euclidean2D.AngleToCounterClock(t1, t3);
                return(a1 < a2);
            }
            else
            {
                double d1 = (test1 - P1).MagSquared();
                double d2 = (test2 - P1).MagSquared();
                return(d1 < d2);
            }
        }
Exemplo n.º 2
0
        public static Vector3D SpiralToIsometric(Vector3D v, int p, int m, int n)
        {
            Complex vc = v.ToComplex();

            v = new Vector3D(Math.Log(vc.Magnitude), vc.Phase);

            Vector3D e1 = new Vector3D(0, 1);
            Vector3D e2;

            switch (p)
            {
            case 3:
                e2 = new Vector3D(); break;

            case 4:
                e2 = new Vector3D(); break;

            case 6:
                e2 = new Vector3D(); break;

            default:
                throw new System.ArgumentException();
            }

            double scale = Math.Sqrt(m * m + n * n);
            double a     = Euclidean2D.AngleToClock(new Vector3D(0, 1), new Vector3D(m, n));

            v.RotateXY(a);          // Rotate
            v *= scale;             // Scale

            v *= Math.Sqrt(2) * Geometry2D.EuclideanHypotenuse / (2 * Math.PI);
            v.RotateXY(Math.PI / 4);
            return(v);
        }
Exemplo n.º 3
0
        private static bool PointOnArcSegment(Vector3D p, Segment seg)
        {
            double   maxAngle = seg.Angle;
            Vector3D v1       = seg.P1 - seg.Center;
            Vector3D v2       = p - seg.Center;

            Debug.Assert(Tolerance.Equal(v1.Abs(), v2.Abs()));
            double angle = seg.Clockwise ?
                           Euclidean2D.AngleToClock(v1, v2) :
                           Euclidean2D.AngleToCounterClock(v1, v2);

            return(Tolerance.LessThanOrEqual(angle, maxAngle));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Normalize so P1 is closest point to origin,
        /// and direction vector is of unit length.
        /// </summary>
        public void NormalizeLine()
        {
            if (!this.IsLine)
            {
                return;
            }

            Vector3D d = P2 - P1;

            d.Normalize();

            P1 = Euclidean2D.ProjectOntoLine(new Vector3D(), P1, P2);

            // ZZZ - Could probably do something more robust to choose proper direction.
            if (Tolerance.GreaterThanOrEqual(Euclidean2D.AngleToClock(d, new Vector3D(1, 0)), Math.PI))
            {
                d *= -1;
            }

            P2 = P1 + d;
        }