Skip to content

Commit

Permalink
支持绘制焦点在 y 轴上的双曲线
Browse files Browse the repository at this point in the history
  • Loading branch information
clover-yan authored and kengwang committed Nov 5, 2023
1 parent e3098d6 commit 40a4b99
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions Ink Canvas/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4748,16 +4748,31 @@ private void MouseTouchMove(Point endP)
{
//第二笔:画双曲线
double k = drawMultiStepShapeSpecialParameter3;
a = Math.Sqrt(Math.Abs((endP.X - iniP.X) * (endP.X - iniP.X) - (endP.Y - iniP.Y) * (endP.Y - iniP.Y) / (k * k)));
b = a * k;
pointList = new List<Point>();
for (double i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5)
{
double rY = Math.Sqrt(Math.Abs(k * k * i * i - b * b));
pointList.Add(new Point(iniP.X + i, iniP.Y - rY));
pointList2.Add(new Point(iniP.X + i, iniP.Y + rY));
pointList3.Add(new Point(iniP.X - i, iniP.Y - rY));
pointList4.Add(new Point(iniP.X - i, iniP.Y + rY));
bool isHyperbolaFocalPointOnXAxis = Math.Abs((endP.Y - iniP.Y) / (endP.X - iniP.X)) < k;
if (isHyperbolaFocalPointOnXAxis) { // 焦点在 x 轴上
a = Math.Sqrt(Math.Abs((endP.X - iniP.X) * (endP.X - iniP.X) - (endP.Y - iniP.Y) * (endP.Y - iniP.Y) / (k * k)));
b = a * k;
pointList = new List<Point>();
for (double i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5)
{
double rY = Math.Sqrt(Math.Abs(k * k * i * i - b * b));
pointList.Add(new Point(iniP.X + i, iniP.Y - rY));
pointList2.Add(new Point(iniP.X + i, iniP.Y + rY));
pointList3.Add(new Point(iniP.X - i, iniP.Y - rY));
pointList4.Add(new Point(iniP.X - i, iniP.Y + rY));
}
} else { // 焦点在 y 轴上
a = Math.Sqrt(Math.Abs((endP.Y - iniP.Y) * (endP.Y - iniP.Y) - (endP.X - iniP.X) * (endP.X - iniP.X) * (k * k)));
b = a / k;
pointList = new List<Point>();
for (double i = a; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5)
{
double rX = Math.Sqrt(Math.Abs(i * i / k / k - b * b));
pointList.Add(new Point(iniP.X - rX, iniP.Y + i));
pointList2.Add(new Point(iniP.X + rX, iniP.Y + i));
pointList3.Add(new Point(iniP.X - rX, iniP.Y - i));
pointList4.Add(new Point(iniP.X + rX, iniP.Y - i));
}
}
try
{
Expand All @@ -4777,12 +4792,12 @@ private void MouseTouchMove(Point endP)
{
//画焦点
c = Math.Sqrt(a * a + b * b);
stylusPoint = new StylusPoint(iniP.X + c, iniP.Y, (float)1.0);
stylusPoint = isHyperbolaFocalPointOnXAxis ? new StylusPoint(iniP.X + c, iniP.Y, (float)1.0) : new StylusPoint(iniP.X, iniP.Y + c, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
stylusPoint = new StylusPoint(iniP.X - c, iniP.Y, (float)1.0);
stylusPoint = isHyperbolaFocalPointOnXAxis ? new StylusPoint(iniP.X - c, iniP.Y, (float)1.0) : new StylusPoint(iniP.X, iniP.Y - c, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
Expand Down

1 comment on commit 40a4b99

@STBBRD
Copy link
Contributor

@STBBRD STBBRD commented on 40a4b99 Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非常好功能

Please sign in to comment.