コード例 #1
0
        internal static float ConvertSweepAngle(float sweepAngle, float startAngle, SpatialTransform transform, CoordinateSystem targetSystem)
        {
            PointF x = new PointF(100, 0);

            PointF[] startVector = new PointF[] { x };
            Matrix   rotation    = new Matrix();

            rotation.Rotate(startAngle);
            rotation.TransformVectors(startVector);

            PointF[] sweepVector = (PointF[])startVector.Clone();
            rotation.Reset();
            rotation.Rotate(sweepAngle);
            rotation.TransformVectors(sweepVector);
            rotation.Dispose();

            SizeF startVectorTransformed, sweepVectorTransformed;

            if (targetSystem == Graphics.CoordinateSystem.Destination)
            {
                startVectorTransformed = transform.ConvertToDestination(new SizeF(startVector[0]));
                sweepVectorTransformed = transform.ConvertToDestination(new SizeF(sweepVector[0]));
            }
            else
            {
                startVectorTransformed = transform.ConvertToSource(new SizeF(startVector[0]));
                sweepVectorTransformed = transform.ConvertToSource(new SizeF(sweepVector[0]));
            }

            // simply return the angle between the start and sweep angle, in the target system.
            return((int)Math.Round(Vector.SubtendedAngle(sweepVectorTransformed.ToPointF(), PointF.Empty, startVectorTransformed.ToPointF())));
        }
コード例 #2
0
        internal static float ConvertStartAngle(float angle, SpatialTransform transform, CoordinateSystem targetSystem)
        {
            PointF xVector = new PointF(100, 0);

            Matrix rotation = new Matrix();

            PointF[] angleVector = new PointF[] { xVector };
            rotation.Rotate(angle);
            rotation.TransformVectors(angleVector);
            rotation.Dispose();

            SizeF xVectorTransformed, angleVectorTransformed;

            if (targetSystem == Graphics.CoordinateSystem.Destination)
            {
                xVectorTransformed     = transform.ConvertToDestination(new SizeF(xVector));
                angleVectorTransformed = transform.ConvertToDestination(new SizeF(angleVector[0]));
            }
            else
            {
                xVectorTransformed     = transform.ConvertToSource(new SizeF(xVector));
                angleVectorTransformed = transform.ConvertToSource(new SizeF(angleVector[0]));
            }

            float xRotationOffset =
                (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector));

            float angleTransformed =
                (int)Math.Round(Vector.SubtendedAngle(angleVectorTransformed.ToPointF(), PointF.Empty, xVectorTransformed.ToPointF()));

            // have to figure out where x-axis moved to and then return the difference between the angle
            // and the x-axis, where both are in 'target' coordinates.
            float returnAngle = angleTransformed + xRotationOffset;

            if (returnAngle < 0)
            {
                returnAngle += 360;
            }

            return(returnAngle);
        }