123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Prism.Mvvm;
- using System.Windows;
- using System.Collections;
- using MathNet.Numerics.LinearAlgebra.Factorization;
- namespace FlowChartModule.绘制模块
- {
- public class BezierCurveModel : BindableBase
- {
- private Point _StartPoint;
- private Point _ControlPoint1 ;
- private Point _ControlPoint2;
- private Point _EndPoint;
- public Point StartPoint
- {
- get
- {
- return _StartPoint;
- }
- set
- {
- ControlPoint1 = CalculateMiddlePointWithSimpleControlPoints(StartPoint, EndPoint, 0.3f);
- ControlPoint2 = CalculateMiddlePointWithSimpleControlPoints(StartPoint, EndPoint, 0.75f);
- SetProperty(ref _StartPoint, value);
- }
- }
- public Point ControlPoint1
- {
- get
- {
-
- return _ControlPoint1;
- }
- set
- {
- SetProperty(ref _ControlPoint1, value);
- }
- }
- public Point ControlPoint2
- {
- get
- {
- return _ControlPoint2;
- }
- set
- {
- SetProperty(ref _ControlPoint2, value);
- }
- }
- public Point EndPoint
- {
- get
- {
- return _EndPoint;
- }
- set
- {
- ControlPoint1 = CalculateMiddlePointWithSimpleControlPoints(StartPoint,EndPoint,0.3f);
- ControlPoint2 = CalculateMiddlePointWithSimpleControlPoints(StartPoint, EndPoint, 0.75f);
- SetProperty(ref _EndPoint, value);
-
- }
- }
- // 计算三阶贝塞尔曲线上指定 t 值的点
- public static Point CalculateCubicBezierPoint(Point p0, Point p1, Point p2, Point p3, double t)
- {
- double u = 1 - t;
- double tt = t * t;
- double uu = u * u;
- double uuu = uu * u;
- double ttt = tt * t;
- double x = uuu * p0.X + 3 * uu * t * p1.X + 3 * u * tt * p2.X + ttt * p3.X;
- double y = uuu * p0.Y + 3 * uu * t * p1.Y + 3 * u * tt * p2.Y + ttt * p3.Y;
- return new Point(x, y);
- }
- // 根据起点和终点简单生成控制点并计算中间点
- public static Point CalculateMiddlePointWithSimpleControlPoints(Point start, Point end, double t)
- {
- // 简单线性插值确定控制点
- Point p1 = new Point(start.X + (end.X - start.X) * 0.25f, start.Y + (end.Y - start.Y) * 0.25f);
- Point p2 = new Point(start.X + (end.X - start.X) * 0.75f, start.Y + (end.Y - start.Y) * 0.75f);
- return CalculateCubicBezierPoint(start, p1, p2, end, t);
- }
- }
- }
|