RadarChart.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Masuit.Tools.Maths
  4. {
  5. public class RadarChart
  6. {
  7. /// <summary>
  8. /// 向量长度集合
  9. /// </summary>
  10. public List<double> Data { get; }
  11. /// <summary>
  12. /// 起始弧度
  13. /// </summary>
  14. public double StartAngle { get; } // 弧度
  15. /// <summary>
  16. /// 多边形
  17. /// </summary>
  18. /// <param name="data">向量长度集合</param>
  19. /// <param name="startAngle">起始弧度</param>
  20. public RadarChart(List<double> data, double startAngle = 0)
  21. {
  22. Data = new List<double>(data);
  23. StartAngle = startAngle;
  24. }
  25. /// <summary>
  26. /// 获取每个点的坐标
  27. /// </summary>
  28. /// <returns></returns>
  29. public List<Point2D> GetPoints()
  30. {
  31. int count = Data.Count;
  32. List<Point2D> result = new List<Point2D>();
  33. for (int i = 0; i < count; i++)
  34. {
  35. double length = Data[i];
  36. double angle = StartAngle + Math.PI * 2 / count * i;
  37. double x = length * Math.Cos(angle);
  38. double y = length * Math.Sin(angle);
  39. result.Add(new Point2D(x, y));
  40. }
  41. return result;
  42. }
  43. }
  44. }