|
@@ -0,0 +1,107 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Drawing;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace OTSMeasureApp._0_OTSModel.OTSDataType
|
|
|
+{
|
|
|
+ public struct SpacePoint
|
|
|
+ {
|
|
|
+ public SpacePoint(double x, double y, double z)
|
|
|
+ {
|
|
|
+ this.x = x;
|
|
|
+ this.y = y;
|
|
|
+ this.z = z;
|
|
|
+ }
|
|
|
+ public double x;
|
|
|
+ public double y;
|
|
|
+ public double z;
|
|
|
+
|
|
|
+ }
|
|
|
+ public struct Vec3
|
|
|
+ {
|
|
|
+ public double a;
|
|
|
+ public double b;
|
|
|
+ public double c;
|
|
|
+
|
|
|
+ }
|
|
|
+ public class CSlopFocusParam
|
|
|
+ {
|
|
|
+ private bool m_IsUsingSlopParam;
|
|
|
+ private Point m_FirstPoint;
|
|
|
+ private double m_FirstWD=0;
|
|
|
+ private Point m_SecondPoint;
|
|
|
+ private double m_SecondWD=0;
|
|
|
+ private Point m_ThirdPoint;
|
|
|
+ private double m_ThirdWD=0;
|
|
|
+
|
|
|
+ public bool IsUsingSlopParam { get => m_IsUsingSlopParam; set => m_IsUsingSlopParam = value; }
|
|
|
+ public Point FirstPoint { get => m_FirstPoint; set => m_FirstPoint = value; }
|
|
|
+ public double FirstWD { get => m_FirstWD; set => m_FirstWD = value; }
|
|
|
+ public Point SecondPoint { get => m_SecondPoint; set => m_SecondPoint = value; }
|
|
|
+ public double SecondWD { get => m_SecondWD; set => m_SecondWD = value; }
|
|
|
+ public Point ThirdPoint { get => m_ThirdPoint; set => m_ThirdPoint = value; }
|
|
|
+ public double ThirdWD { get => m_ThirdWD; set => m_ThirdWD = value; }
|
|
|
+ public double GetWD(Point currentPoint)
|
|
|
+ {
|
|
|
+ double a=0, b=0, c=0, d=0;
|
|
|
+ SpacePoint p1 = new SpacePoint(FirstPoint.X,FirstPoint.Y,FirstWD);
|
|
|
+ SpacePoint p2 = new SpacePoint(SecondPoint.X, SecondPoint.Y, SecondWD);
|
|
|
+ SpacePoint p3 = new SpacePoint(ThirdPoint.X, ThirdPoint.Y, ThirdWD);
|
|
|
+ get_panel(p1, p2, p3,ref a,ref b,ref c, ref d);
|
|
|
+ double wd;
|
|
|
+ wd = ((0 - d) - (a * currentPoint.X + b * currentPoint.Y)) / c;
|
|
|
+ return wd;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //已知3点坐标,求平面ax+by+cz+d=0;
|
|
|
+
|
|
|
+ void get_panel(SpacePoint p1, SpacePoint p2, SpacePoint p3, ref double a, ref double b, ref double c, ref double d)
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ a = (p2.y - p1.y) * (p3.z - p1.z) - (p2.z - p1.z) * (p3.y - p1.y);
|
|
|
+
|
|
|
+ b = (p2.z - p1.z) * (p3.x - p1.x) - (p2.x - p1.x) * (p3.z - p1.z);
|
|
|
+
|
|
|
+ c = (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
|
|
|
+
|
|
|
+ d = 0 - (a * p1.x + b * p1.y + c * p1.z);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 已知三点坐标,求法向量
|
|
|
+
|
|
|
+ Vec3 get_Normal(SpacePoint p1, SpacePoint p2, SpacePoint p3)
|
|
|
+
|
|
|
+ {
|
|
|
+ double a, b, c;
|
|
|
+ a = (p2.y - p1.y) * (p3.z - p1.z) - (p2.z - p1.z) * (p3.y - p1.y);
|
|
|
+
|
|
|
+ b = (p2.z - p1.z) * (p3.x - p1.x) - (p2.x - p1.x) * (p3.z - p1.z);
|
|
|
+
|
|
|
+ c = (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
|
|
|
+
|
|
|
+ Vec3 v= new Vec3();
|
|
|
+ v.a = a;
|
|
|
+ v.b = b;
|
|
|
+ v.c = c;
|
|
|
+ return v;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //点到平面距离
|
|
|
+
|
|
|
+ double dis_pt2panel(SpacePoint pt, double a, double b, double c, double d)
|
|
|
+ {
|
|
|
+
|
|
|
+ return Math.Abs(a * pt.x + b * pt.y + c * pt.z + d) / Math.Sqrt(a * a + b * b + c * c);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|