From b9810325fa77d608a9e446c89fe7b76ff6e54899 Mon Sep 17 00:00:00 2001 From: facat Date: Thu, 10 Jun 2021 00:25:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=89=BE=E6=9C=80=E7=9F=AD?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E5=8A=9F=E8=83=BD=E3=80=82=20Signed-off-by:?= =?UTF-8?q?=20facat=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 12 +++++++++- TransmissionGraphic.csproj | 1 + src/Graphic/Canvas.cs | 26 ++++++++++++++++++-- src/Graphic/Ruler.cs | 49 ++++++++++++++++++++++++++++++++++++++ src/Type3D/Vector3D.cs | 8 +++++++ 5 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/Graphic/Ruler.cs diff --git a/Program.cs b/Program.cs index 163fa86..161987b 100644 --- a/Program.cs +++ b/Program.cs @@ -20,8 +20,18 @@ namespace TransmissionGraphic Matrix sag_points = sag_and_value.Item1; double sag_value = sag_and_value.Item2; canvas.draw(sag_points); - canvas.draw(line.swing(30 / 180 * Math.PI)); + canvas.text(String.Format("sag:{0}",sag_value), new TGVector3D(sag_points.At(1,0),sag_points.At(1,1),sag_points.At(1,2))); + canvas.draw(line.swing(1.0*90 / 180 * Math.PI)); + Line line111 =new Line(new TGVector3D(50, 30, 0), new TGVector3D(430, 90, 1), 0.35 * 1e-3, 800); + Matrix line111swing=line111.swing(1.0*45/180*Math.PI); + canvas.draw(line111swing); + Ruler ruler = new Ruler(line.curve(), line111swing); + Tuple closest_distance = ruler.closest_distance(); + canvas.draw(closest_distance.Item2, closest_distance.Item3); canvas.save("abc.dxf"); + Console.WriteLine(closest_distance.Item1); + Console.ReadKey(); + } } diff --git a/TransmissionGraphic.csproj b/TransmissionGraphic.csproj index 7b58ed9..b20a014 100644 --- a/TransmissionGraphic.csproj +++ b/TransmissionGraphic.csproj @@ -57,6 +57,7 @@ + diff --git a/src/Graphic/Canvas.cs b/src/Graphic/Canvas.cs index de01fa6..9b04937 100644 --- a/src/Graphic/Canvas.cs +++ b/src/Graphic/Canvas.cs @@ -6,6 +6,7 @@ using WW.Cad.Model; using WW.Cad.Model.Entities; using WW.Cad.IO; using MathNet.Numerics.LinearAlgebra; +using TransmissionGraphic.Type3D; namespace TransmissionGraphic.Graphic { @@ -25,7 +26,7 @@ namespace TransmissionGraphic.Graphic public void draw(Matrix points) { - DxfModel model=this._model; + DxfModel model = this._model; DxfPolyline3D polyline = new DxfPolyline3D(); DxfVertex3D[] vertex = new DxfVertex3D[points.RowCount]; for (int foo = 0; foo < points.RowCount; foo++) @@ -37,11 +38,32 @@ namespace TransmissionGraphic.Graphic model.Entities.Add(polyline); } + public void draw(TGVector3D point1, TGVector3D point2) + { + DxfModel model = this._model; + DxfVertex3D[] vertex = new DxfVertex3D[] + { + new DxfVertex3D(point1.x,point1.y,point1.z), + new DxfVertex3D(point2.x,point2.y,point2.z) + }; + DxfPolyline3D polyline = new DxfPolyline3D(); + polyline.Closed = false; + polyline.Vertices.AddRange(vertex); + model.Entities.Add(polyline); + } + public void save(string filePath) { DxfModel model = this._model; DxfWriter.Write(filePath, model); - + + } + + public void text(string text, TGVector3D point) + { + DxfModel model = this._model; + model.Entities.Add(new DxfText(text, new WW.Math.Point3D(point.x, point.y, point.z), 1d)); + } } } diff --git a/src/Graphic/Ruler.cs b/src/Graphic/Ruler.cs new file mode 100644 index 0000000..f0738f7 --- /dev/null +++ b/src/Graphic/Ruler.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TransmissionGraphic.Type3D; +using MathNet.Numerics.LinearAlgebra; + +namespace TransmissionGraphic.Graphic +{ + class Ruler + { + private Matrix _curve_points1; + private Matrix _curve_points2; + public Ruler(Matrix curve_points1, Matrix curve_points2) + { + this._curve_points1 = curve_points1; + this._curve_points2 = curve_points2; + } + + public Tuple closest_distance() + { + Matrix curve_points1 = this._curve_points1; + Matrix curve_points2 = this._curve_points2; + double closest = 999999999999; + Vector closest_poc1 = null; + Vector closest_poc2 = null; + for (int foo = 0; foo < curve_points1.RowCount; foo++) + { + Vector poc1 = curve_points1.Row(foo);// # point of curve 1 + for (int bar = 0; bar < curve_points2.RowCount; bar++) + { + Vector poc2 = curve_points2.Row(bar); + double distance = (poc1 - poc2).L1Norm(); + if (distance < closest) + { + closest_poc1 = poc1; + closest_poc2 = poc2; + closest = distance; + + } + + } + + } + return new Tuple(closest, new TGVector3D(closest_poc1), new TGVector3D(closest_poc2)); + + } + } +} diff --git a/src/Type3D/Vector3D.cs b/src/Type3D/Vector3D.cs index de9f8a3..19b5920 100644 --- a/src/Type3D/Vector3D.cs +++ b/src/Type3D/Vector3D.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using MathNet.Numerics.LinearAlgebra; namespace TransmissionGraphic.Type3D { @@ -16,6 +17,13 @@ namespace TransmissionGraphic.Type3D this.y = y; this.z = z; } + + public TGVector3D(Vector point) + { + this.x = point.At(0); + this.y = point.At(1); + this.z = point.At(2); + } public static TGVector3D operator- (TGVector3D me, TGVector3D other)