■ 나선형 포인트 리스트를 구하는 방법을 보여준다.
▶ 예제 코드 (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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
using System; using System.Collections.Generic; /// <summary> /// Double형 Point /// </summary> public struct DoublePoint { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// X 좌표 /// </summary> private double x; /// <summary> /// Y 좌표 /// </summary> private double y; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region X 좌표 - X /// <summary> /// X 좌표 /// </summary> public double X { get { return this.x; } set { this.x = value; } } #endregion #region Y 좌표 - Y /// <summary> /// Y 좌표 /// </summary> public double Y { get { return this.y; } set { this.y = value; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DoublePoint(x, y) /// <summary> /// 생성자 /// </summary> /// <param name="x">X 좌표</param> /// <param name="y">Y 좌표</param> /// <returns></returns> public DoublePoint(double x, double y) { this.x = x; this.y = y; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return string.Format("({0}, {1})", this.x, this.y); } #endregion } #region 나선형 포인트 리스트 구하기 - GetSpiralPointList(centerPoint, radius, stepAngle, spiralAngle) /// <summary> /// 나선형 포인트 리스트 구하기 /// </summary> /// <param name="centerPoint">중심점</param> /// <param name="radius">반경</param> /// <param name="stepAngle">단계 각도</param> /// <param name="spiralAngle">나선 각도</param> /// <returns>나선형 포인트 리스트</returns> public List<DoublePoint> GetSpiralPointList(DoublePoint centerPoint, double radius, double stepAngle, double spiralAngle) { List<DoublePoint> list = new List<DoublePoint>(); for(double angle = 0d; angle < spiralAngle; angle += stepAngle) { double saleRadius = radius * angle / spiralAngle; double radian = Math.PI * angle / 180d; double x = centerPoint.X + saleRadius * Math.Cos(radian); double y = centerPoint.Y + saleRadius * Math.Sin(radian); list.Add(new DoublePoint(x, y)); } return list; } #endregion |