CSlopFocusParam.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace OTSMeasureApp._0_OTSModel.OTSDataType
  8. {
  9. public struct SpacePoint
  10. {
  11. public SpacePoint(double x, double y, double z)
  12. {
  13. this.x = x;
  14. this.y = y;
  15. this.z = z;
  16. }
  17. public double x;
  18. public double y;
  19. public double z;
  20. }
  21. public struct Vec3
  22. {
  23. public double a;
  24. public double b;
  25. public double c;
  26. }
  27. public class CSlopFocusParam
  28. {
  29. private bool m_IsUsingSlopParam=false;
  30. private Point m_FirstPoint;
  31. private double m_FirstWD=0;
  32. private Point m_SecondPoint;
  33. private double m_SecondWD=0;
  34. private Point m_ThirdPoint;
  35. private double m_ThirdWD=0;
  36. public bool IsUsingSlopParam { get => m_IsUsingSlopParam; set => m_IsUsingSlopParam = value; }
  37. public Point FirstPoint { get => m_FirstPoint; set => m_FirstPoint = value; }
  38. public double FirstWD { get => m_FirstWD; set => m_FirstWD = value; }
  39. public Point SecondPoint { get => m_SecondPoint; set => m_SecondPoint = value; }
  40. public double SecondWD { get => m_SecondWD; set => m_SecondWD = value; }
  41. public Point ThirdPoint { get => m_ThirdPoint; set => m_ThirdPoint = value; }
  42. public double ThirdWD { get => m_ThirdWD; set => m_ThirdWD = value; }
  43. public double GetWD(PointF currentPoint)
  44. {
  45. double a=0, b=0, c=0, d=0;
  46. SpacePoint p1 = new SpacePoint(FirstPoint.X,FirstPoint.Y,FirstWD);
  47. SpacePoint p2 = new SpacePoint(SecondPoint.X, SecondPoint.Y, SecondWD);
  48. SpacePoint p3 = new SpacePoint(ThirdPoint.X, ThirdPoint.Y, ThirdWD);
  49. get_panel(p1, p2, p3,ref a,ref b,ref c, ref d);
  50. double wd;
  51. wd = ((0 - d) - (a * currentPoint.X + b * currentPoint.Y)) / c;
  52. return wd;
  53. }
  54. //已知3点坐标,求平面ax+by+cz+d=0;
  55. void get_panel(SpacePoint p1, SpacePoint p2, SpacePoint p3, ref double a, ref double b, ref double c, ref double d)
  56. {
  57. a = (p2.y - p1.y) * (p3.z - p1.z) - (p2.z - p1.z) * (p3.y - p1.y);
  58. b = (p2.z - p1.z) * (p3.x - p1.x) - (p2.x - p1.x) * (p3.z - p1.z);
  59. c = (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
  60. d = 0 - (a * p1.x + b * p1.y + c * p1.z);
  61. }
  62. // 已知三点坐标,求法向量
  63. Vec3 get_Normal(SpacePoint p1, SpacePoint p2, SpacePoint p3)
  64. {
  65. double a, b, c;
  66. a = (p2.y - p1.y) * (p3.z - p1.z) - (p2.z - p1.z) * (p3.y - p1.y);
  67. b = (p2.z - p1.z) * (p3.x - p1.x) - (p2.x - p1.x) * (p3.z - p1.z);
  68. c = (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
  69. Vec3 v= new Vec3();
  70. v.a = a;
  71. v.b = b;
  72. v.c = c;
  73. return v;
  74. }
  75. //点到平面距离
  76. double dis_pt2panel(SpacePoint pt, double a, double b, double c, double d)
  77. {
  78. return Math.Abs(a * pt.x + b * pt.y + c * pt.z + d) / Math.Sqrt(a * a + b * b + c * c);
  79. }
  80. }
  81. }