■ Point 구조체에서 회전하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
using System; using System.Windows; #region 회전하기 - Rotate(sourcePoint, centerPoint, rotateAngle) /// <summary> /// 회전하기 /// </summary> /// <param name="sourcePoint">소스 포인트</param> /// <param name="centerPoint">중심 포인트</param> /// <param name="rotateAngle">회전 각도</param> /// <returns>회전 포인트</returns> public Point Rotate(Point sourcePoint, Point centerPoint, double rotateAngle) { Point targetPoint = new Point(); double radian = rotateAngle / 180 * Math.PI; targetPoint.X = Math.Cos(radian) * (sourcePoint.X - centerPoint.X) - Math.Sin(radian) * (sourcePoint.Y - centerPoint.Y) + centerPoint.X; targetPoint.Y = Math.Sin(radian) * (sourcePoint.X - centerPoint.X) + Math.Cos(radian) * (sourcePoint.Y - centerPoint.Y) + centerPoint.Y; return targetPoint; } #endregion |