/Controls/HelixToolkit.Wpf/Geometry/Plane3D.cs

https://bitbucket.org/kubrakms/thermalconductivity · C# · 163 lines · 62 code · 24 blank · 77 comment · 6 complexity · 8160e39e1ca62c592fbfe44cc8fb6444 MD5 · raw file

  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="Plane3D.cs" company="Helix 3D Toolkit">
  3. // http://helixtoolkit.codeplex.com, license: Ms-PL
  4. // </copyright>
  5. // --------------------------------------------------------------------------------------------------------------------
  6. namespace HelixToolkit.Wpf
  7. {
  8. using System.Windows.Media.Media3D;
  9. /// <summary>
  10. /// Represents a plane.
  11. /// </summary>
  12. public class Plane3D
  13. {
  14. #region Constants and Fields
  15. /// <summary>
  16. /// The normal.
  17. /// </summary>
  18. internal Vector3D normal;
  19. /// <summary>
  20. /// The position.
  21. /// </summary>
  22. internal Point3D position;
  23. #endregion
  24. #region Constructors and Destructors
  25. /// <summary>
  26. /// Initializes a new instance of the <see cref = "Plane3D" /> class.
  27. /// </summary>
  28. public Plane3D()
  29. {
  30. // Width=50;
  31. // Height=50;
  32. }
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="Plane3D"/> class.
  35. /// </summary>
  36. /// <param name="p0">
  37. /// The p0.
  38. /// </param>
  39. /// <param name="n">
  40. /// The n.
  41. /// </param>
  42. public Plane3D(Point3D p0, Vector3D n)
  43. {
  44. this.Position = p0;
  45. this.Normal = n;
  46. }
  47. #endregion
  48. #region Public Properties
  49. /// <summary>
  50. /// Gets or sets the normal.
  51. /// </summary>
  52. /// <value>The normal.</value>
  53. public Vector3D Normal
  54. {
  55. get
  56. {
  57. return this.normal;
  58. }
  59. set
  60. {
  61. this.normal = value;
  62. }
  63. }
  64. /// <summary>
  65. /// Gets or sets the position.
  66. /// </summary>
  67. /// <value>The position.</value>
  68. public Point3D Position
  69. {
  70. get
  71. {
  72. return this.position;
  73. }
  74. set
  75. {
  76. this.position = value;
  77. }
  78. }
  79. #endregion
  80. #region Public Methods
  81. /// <summary>
  82. /// Finds the intersection between the plane and the line (la,lb).
  83. /// </summary>
  84. /// <param name="la">
  85. /// The la.
  86. /// </param>
  87. /// <param name="lb">
  88. /// The lb.
  89. /// </param>
  90. /// <returns>
  91. /// The intersection point.
  92. /// </returns>
  93. public Point3D? LineIntersection(Point3D la, Point3D lb)
  94. {
  95. // http://en.wikipedia.org/wiki/Line-plane_intersection
  96. var l = lb - la;
  97. double a = Vector3D.DotProduct(this.position - la, this.normal);
  98. double b = Vector3D.DotProduct(l, this.normal);
  99. if (a == 0 && b == 0)
  100. {
  101. return null;
  102. }
  103. if (b == 0)
  104. {
  105. return null;
  106. }
  107. return la + (a / b) * l;
  108. }
  109. #endregion
  110. // public void SetYZ(double x, int dir)
  111. // {
  112. // Position = new Point3D(x, 0, Height / 2);
  113. // Normal = new Vector3D(dir, 0, 0);
  114. // Up = new Vector3D(0, 0, 1);
  115. // }
  116. // public void SetXY(double z, int dir)
  117. // {
  118. // Position = new Point3D(0, 0, z);
  119. // Normal = new Vector3D(0, 0, dir);
  120. // Up = new Vector3D(1, 0, 0);
  121. // }
  122. // public void SetXZ(double y, int dir)
  123. // {
  124. // Position = new Point3D(0, y, 0);
  125. // Normal = new Vector3D(0, dir, 0);
  126. // Up = new Vector3D(1, 0, 0);
  127. // }
  128. // public Point3D[] GetCornerPoints()
  129. // {
  130. // var pts = new Point3D[4];
  131. // Vector3D right = Vector3D.CrossProduct(Normal, Up);
  132. // pts[0] = Position + (-right * 0.5 * Width - Up * 0.5 * Height);
  133. // pts[1] = Position + (right * 0.5 * Width - Up * 0.5 * Height);
  134. // pts[2] = Position + (right * 0.5 * Width + Up * 0.5 * Height);
  135. // pts[3] = Position + (-right * 0.5 * Width + Up * 0.5 * Height);
  136. // return pts;
  137. // }
  138. }
  139. }