mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
{
|
|
public static class DrawingHelper
|
|
{
|
|
public static List<Point> GetPoints(Point startPoint, double angle, List<Tuple<double, double>> angleAndWidth)
|
|
{
|
|
List<Point> points = new List<Point>();
|
|
points.Add(startPoint);
|
|
|
|
Point thisPoint= startPoint;
|
|
double thisAngle = angle;
|
|
|
|
Point nextPoint;
|
|
foreach (var item in angleAndWidth)
|
|
{
|
|
nextPoint = GetEndPointByTrigonometric(thisPoint, thisAngle, item.Item1);
|
|
//if (thisPoint != nextPoint)
|
|
{
|
|
points.Add(nextPoint);
|
|
}
|
|
|
|
thisPoint = nextPoint;
|
|
thisAngle = thisAngle + item.Item2;
|
|
}
|
|
|
|
|
|
return points;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 通过三角函数求终点坐标
|
|
/// </summary>
|
|
/// <param name="angle">角度</param>
|
|
/// <param name="startPoint">起点</param>
|
|
/// <param name="distance">距离</param>
|
|
/// <returns>终点坐标</returns>
|
|
public static Point GetEndPointByTrigonometric(Point startPoint, double angle, double distance)
|
|
{
|
|
//角度转弧度
|
|
var radian = (angle * Math.PI) / 180;
|
|
|
|
//计算新坐标 r 就是两者的距离
|
|
Point endPoint = new Point(startPoint.X + distance * Math.Cos(radian), startPoint.Y + distance * Math.Sin(radian));
|
|
|
|
return endPoint;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过三角函数求终点坐标
|
|
/// </summary>
|
|
/// <param name="angle">角度</param>
|
|
/// <param name="startPoint">起点</param>
|
|
/// <param name="distance">距离</param>
|
|
/// <returns>终点坐标</returns>
|
|
public static Point GetEndPointByDirection(Point startPoint, double direction, double distance)
|
|
{
|
|
return GetEndPointByTrigonometric(startPoint, direction - 90, distance);
|
|
}
|
|
|
|
}
|
|
}
|