mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-28 12:13:25 +08:00
简单画线算法
This commit is contained in:
53
AIStudio.Wpf.DiagramDesigner/Helpers/DrawingHelper.cs
Normal file
53
AIStudio.Wpf.DiagramDesigner/Helpers/DrawingHelper.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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);
|
||||
points.Add((Point)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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user