增加sag和swing,不考虑在这些函数里面绘图。

Signed-off-by: facat <facat@facat.com>
This commit is contained in:
facat 2021-06-09 23:48:26 +08:00
parent 53bc81b989
commit bde8c2f462
2 changed files with 54 additions and 6 deletions

View File

@ -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<Matrix<double>, double> sag_and_value = line.sag();
Matrix<double> 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");
}

View File

@ -18,8 +18,7 @@ namespace TransmissionGraphic.Graphic
private double _span;
private Matrix<double> _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<double> curve(bool draw = false)
public Matrix<double> curve()
{
if (this._points != null)
{
@ -53,7 +51,7 @@ namespace TransmissionGraphic.Graphic
double span = xy_project.abs();
this._span = span;
Vector<double> span_l = Vector<double>.Build.DenseOfArray(Generate.LinearSpaced(n_point, 0, span)); // 档距
Vector<double> z_points = start_p.z + span_l * height / span - span_l.PointwiseMultiply(span - span_l)* tension_k / Math.Cos(Math.Atan(height / span));
Vector<double> 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<double> points = rotation.rotate(Matrix<double>.Build.DenseOfArray(p_points));
this._points = points;
return points;
}
public Matrix<double> swing(double angel)
{
if (this._points == null)
{
this.curve();
}
Matrix<double> 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<double> swing_point = swing_rotation.rotate(points);
return swing_point;
}
public Tuple<Matrix<double>, 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<double> 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<double> p_sag_points = Matrix<double>.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<double> sag_points = rotation.rotate(p_sag_points);
double sag_value = start_p.z + middle_span * height / span - middle_z;
return new Tuple<Matrix<double>, double>(sag_points, sag_value);
}
}
}