From 40a4b9905ac1f261dcdc722c72126ba8a86c292b Mon Sep 17 00:00:00 2001 From: clover_yan Date: Sun, 5 Nov 2023 10:48:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=BB=98=E5=88=B6=E7=84=A6?= =?UTF-8?q?=E7=82=B9=E5=9C=A8=20y=20=E8=BD=B4=E4=B8=8A=E7=9A=84=E5=8F=8C?= =?UTF-8?q?=E6=9B=B2=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml.cs | 39 ++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 4472c5a..49a07ab 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -4748,16 +4748,31 @@ namespace Ink_Canvas { //第二笔:画双曲线 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(); - 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(); + 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(); + 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 { @@ -4777,12 +4792,12 @@ namespace Ink_Canvas { //画焦点 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() };