■ 다각형 포인트 리스트를 구하는 방법을 보여준다.
▶ 예제 코드 (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 |
using System; using System.Collections.Generic; #region 다각형 포인트 리스트 구하기 - GetPolygonPointList(centerPoint, radius, sideCount) /// <summary> /// 다각형 포인트 리스트 구하기 /// </summary> /// <param name="centerPoint">중심점</param> /// <param name="radius">반경</param> /// <param name="sideCount">면 수</param> /// <returns>다각형 포인트 리스트</returns> public List<DoublePoint> GetPolygonPointList(DoublePoint centerPoint, double radius, int sideCount) { List<DoublePoint> list = new List<DoublePoint>(); for(int vertex = 0; vertex < sideCount; vertex++) { double radian = (double)vertex * 2d * Math.PI / (double)sideCount; double x = centerPoint.X + radius * Math.Sin(radian); double y = centerPoint.Y - radius * Math.Cos(radian); list.Add(new DoublePoint(x, y)); } return list; } #endregion /// <summary> /// 실수 포인트 /// </summary> public class DoublePoint { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region X - X /// <summary> /// X /// </summary> public double X { get; set; } #endregion #region Y - Y /// <summary> /// Y /// </summary> public double Y { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DoublePoint(x, y) /// <summary> /// 생성자 /// </summary> /// <param name="x">X</param> /// <param name="y">Y</param> public DoublePoint(double x, double y) { X = x; Y = y; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return string.Format("X={0},Y={1}", X, Y); } #endregion } |