예제 #1
0
        /// <summary>
        /// Rounds the X and Y members of the specified <see cref="RadPoint"/>.
        /// </summary>
        public static RadPoint Round(RadPoint point)
        {
            point.X = Math.Round(point.X);
            point.Y = Math.Round(point.Y);

            return(point);
        }
예제 #2
0
        /// <summary>
        /// Converts cartesian into polar coordinates.
        /// </summary>
        /// <param name="point">The point we are converting.</param>
        /// <param name="centerPoint">The (0,0) point of the the coordinate system.</param>
        /// <param name="reverse">True to reverse the calculated angle using the (360 - angle) expression, false otherwise.</param>
        /// <returns> Coordinates as radius and angle (in degrees).</returns>
        internal static Tuple <double, double> ToPolarCoordinates(RadPoint point, RadPoint centerPoint, bool reverse = false)
        {
            var xOffset = point.X - centerPoint.X;
            var yLength = Math.Abs(point.Y - centerPoint.Y);

            var pointRadius = Math.Sqrt(xOffset * xOffset + yLength * yLength);

            double pointAngle = Math.Asin(yLength / pointRadius) * 180 / Math.PI;

            // Determine quadrant and adjust the point angle accordingly
            if (centerPoint.X < point.X && centerPoint.Y > point.Y)
            {
                // I quadrant
                pointAngle = 360 - pointAngle;
            }
            else if (centerPoint.X >= point.X && centerPoint.Y > point.Y)
            {
                // II quadrant
                pointAngle += 180;
            }
            else if (centerPoint.X >= point.X && centerPoint.Y <= point.Y)
            {
                // III quadrant
                pointAngle = 180 - pointAngle;
            }

            if (reverse)
            {
                pointAngle = (360 - pointAngle) % 360;
            }

            return(new Tuple <double, double>(pointRadius, pointAngle));
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RadRect" /> struct.
 /// </summary>
 /// <param name="point1">The point1.</param>
 /// <param name="point2">The point2.</param>
 public RadRect(RadPoint point1, RadPoint point2)
 {
     this.X      = Math.Min(point1.X, point2.X);
     this.Y      = Math.Min(point1.Y, point2.Y);
     this.Width  = Math.Max(Math.Max(point1.X, point2.X) - this.X, 0);
     this.Height = Math.Max(Math.Max(point1.Y, point2.Y) - this.Y, 0);
 }
예제 #4
0
        /// <summary>
        /// Gets the point that lies on the arc segment of the ellipse, described by the center and radius parameters.
        /// </summary>
        public static RadPoint GetArcPoint(double angle, RadPoint center, double radius)
        {
            double angleInRad = angle * RadMath.DegToRadFactor;

            double x = center.X + (Math.Cos(angleInRad) * radius);
            double y = center.Y + (Math.Sin(angleInRad) * radius);

            return(new RadPoint(x, y));
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RadCircle"/> struct.
 /// </summary>
 /// <param name="center">The center.</param>
 /// <param name="radius">The radius.</param>
 public RadCircle(RadPoint center, double radius)
 {
     this.Center = center;
     this.Radius = radius;
 }
예제 #6
0
 public static Point ToPoint(this RadPoint point)
 {
     return(new Point(point.X, point.Y));
 }