diff --git a/Program.cs b/Program.cs index a5906c4..163fa86 100644 --- a/Program.cs +++ b/Program.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using TransmissionGraphic.Graphic; using TransmissionGraphic.Type3D; +using MathNet.Numerics.LinearAlgebra; namespace TransmissionGraphic { @@ -13,8 +14,13 @@ namespace TransmissionGraphic { Canvas canvas = new Canvas(); canvas.init_canvas(); - Line line = new Line(canvas,new TGVector3D(10, 20, 10), new TGVector3D(400, 25, 35), 0.32e-3, 400); + Line line = new Line(new TGVector3D(10, 20, 10), new TGVector3D(400, 25, 35), 0.32e-3, 400); canvas.draw(line.curve()); + Tuple, double> sag_and_value = line.sag(); + 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.save("abc.dxf"); } diff --git a/src/Graphic/Line.cs b/src/Graphic/Line.cs index 8513956..1ab7b67 100644 --- a/src/Graphic/Line.cs +++ b/src/Graphic/Line.cs @@ -18,8 +18,7 @@ namespace TransmissionGraphic.Graphic private double _span; private Matrix _points; private Rotation _rotation; - private Canvas _canvas; - public Line(Canvas canvas, TGVector3D start_p, TGVector3D end_p, double tension_k, int n_point) + public Line(TGVector3D start_p, TGVector3D end_p, double tension_k, int n_point) { this._start_p = start_p; this._end_p = end_p; @@ -28,11 +27,10 @@ namespace TransmissionGraphic.Graphic this._span = 0; this._points = null; this._rotation = null; - this._canvas = canvas; } - public Matrix curve(bool draw = false) + public Matrix curve() { if (this._points != null) { @@ -53,7 +51,7 @@ namespace TransmissionGraphic.Graphic double span = xy_project.abs(); this._span = span; Vector span_l = Vector.Build.DenseOfArray(Generate.LinearSpaced(n_point, 0, span)); // 档距 - Vector z_points = start_p.z + span_l * height / span - span_l.PointwiseMultiply(span - span_l)* tension_k / Math.Cos(Math.Atan(height / span)); + Vector z_points = start_p.z + span_l * height / span - span_l.PointwiseMultiply(span - span_l) * tension_k / Math.Cos(Math.Atan(height / span)); double[,] p_points = new double[n_point, 3]; for (int foo = 0; foo < n_point; foo++) { @@ -66,7 +64,51 @@ namespace TransmissionGraphic.Graphic this._rotation = rotation; Matrix points = rotation.rotate(Matrix.Build.DenseOfArray(p_points)); + this._points = points; return points; } + + public Matrix swing(double angel) + { + if (this._points == null) + { + this.curve(); + } + Matrix points = this._points; + TGVector3D start_p = this._start_p; + TGVector3D end_p = this._end_p; + Rotation swing_rotation = new Rotation( + angel, + new TGVector3D(start_p.x, start_p.y, start_p.z), + new TGVector3D(end_p.x, end_p.y, end_p.z) + ); + Matrix swing_point = swing_rotation.rotate(points); + return swing_point; + } + + public Tuple, double> sag() + { + TGVector3D start_p = this._start_p; + TGVector3D end_p = this._end_p; + double span = this._span; + double height = end_p.z - start_p.z; + double middle_span = span / 2; + Matrix points = this._points; + int n_point = this._n_point; + double middle_z = points.At(Convert.ToInt32(n_point / 2), 2); + Rotation rotation = this._rotation; + Matrix p_sag_points = Matrix.Build.DenseOfArray(new double[,] { + {start_p.x, start_p.y, start_p.z}, + { middle_span + start_p.x, start_p.y, start_p.z + middle_span * height / span }, + {middle_span + start_p.x, start_p.y, middle_z}, + { middle_span + start_p.x, start_p.y, start_p.z + middle_span * height / span }, + {start_p.x + span, start_p.y, end_p.z}, + });// 旋转前的值 + Matrix sag_points = rotation.rotate(p_sag_points); + double sag_value = start_p.z + middle_span * height / span - middle_z; + return new Tuple, double>(sag_points, sag_value); + } + + } }