Plane-a1a3fd52.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './Math-fa6e45cb', './Cartesian2-2a723276', './Transforms-65aba0a4'], function (exports, defined, Check, freezeObject, _Math, Cartesian2, Transforms) { 'use strict';
  3. /**
  4. * A plane in Hessian Normal Form defined by
  5. * <pre>
  6. * ax + by + cz + d = 0
  7. * </pre>
  8. * where (a, b, c) is the plane's <code>normal</code>, d is the signed
  9. * <code>distance</code> to the plane, and (x, y, z) is any point on
  10. * the plane.
  11. *
  12. * @alias Plane
  13. * @constructor
  14. *
  15. * @param {Cartesian3} normal The plane's normal (normalized).
  16. * @param {Number} distance The shortest distance from the origin to the plane. The sign of
  17. * <code>distance</code> determines which side of the plane the origin
  18. * is on. If <code>distance</code> is positive, the origin is in the half-space
  19. * in the direction of the normal; if negative, the origin is in the half-space
  20. * opposite to the normal; if zero, the plane passes through the origin.
  21. *
  22. * @example
  23. * // The plane x=0
  24. * var plane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0);
  25. *
  26. * @exception {DeveloperError} Normal must be normalized
  27. */
  28. function Plane(normal, distance) {
  29. //>>includeStart('debug', pragmas.debug);
  30. Check.Check.typeOf.object('normal', normal);
  31. if (!_Math.CesiumMath.equalsEpsilon(Cartesian2.Cartesian3.magnitude(normal), 1.0, _Math.CesiumMath.EPSILON6)) {
  32. throw new Check.DeveloperError('normal must be normalized.');
  33. }
  34. Check.Check.typeOf.number('distance', distance);
  35. //>>includeEnd('debug');
  36. /**
  37. * The plane's normal.
  38. *
  39. * @type {Cartesian3}
  40. */
  41. this.normal = Cartesian2.Cartesian3.clone(normal);
  42. /**
  43. * The shortest distance from the origin to the plane. The sign of
  44. * <code>distance</code> determines which side of the plane the origin
  45. * is on. If <code>distance</code> is positive, the origin is in the half-space
  46. * in the direction of the normal; if negative, the origin is in the half-space
  47. * opposite to the normal; if zero, the plane passes through the origin.
  48. *
  49. * @type {Number}
  50. */
  51. this.distance = distance;
  52. }
  53. /**
  54. * Creates a plane from a normal and a point on the plane.
  55. *
  56. * @param {Cartesian3} point The point on the plane.
  57. * @param {Cartesian3} normal The plane's normal (normalized).
  58. * @param {Plane} [result] The object onto which to store the result.
  59. * @returns {Plane} A new plane instance or the modified result parameter.
  60. *
  61. * @example
  62. * var point = Cesium.Cartesian3.fromDegrees(-72.0, 40.0);
  63. * var normal = ellipsoid.geodeticSurfaceNormal(point);
  64. * var tangentPlane = Cesium.Plane.fromPointNormal(point, normal);
  65. *
  66. * @exception {DeveloperError} Normal must be normalized
  67. */
  68. Plane.fromPointNormal = function(point, normal, result) {
  69. //>>includeStart('debug', pragmas.debug);
  70. Check.Check.typeOf.object('point', point);
  71. Check.Check.typeOf.object('normal', normal);
  72. if (!_Math.CesiumMath.equalsEpsilon(Cartesian2.Cartesian3.magnitude(normal), 1.0, _Math.CesiumMath.EPSILON6)) {
  73. throw new Check.DeveloperError('normal must be normalized.');
  74. }
  75. //>>includeEnd('debug');
  76. var distance = -Cartesian2.Cartesian3.dot(normal, point);
  77. if (!defined.defined(result)) {
  78. return new Plane(normal, distance);
  79. }
  80. Cartesian2.Cartesian3.clone(normal, result.normal);
  81. result.distance = distance;
  82. return result;
  83. };
  84. var scratchNormal = new Cartesian2.Cartesian3();
  85. /**
  86. * Creates a plane from the general equation
  87. *
  88. * @param {Cartesian4} coefficients The plane's normal (normalized).
  89. * @param {Plane} [result] The object onto which to store the result.
  90. * @returns {Plane} A new plane instance or the modified result parameter.
  91. *
  92. * @exception {DeveloperError} Normal must be normalized
  93. */
  94. Plane.fromCartesian4 = function(coefficients, result) {
  95. //>>includeStart('debug', pragmas.debug);
  96. Check.Check.typeOf.object('coefficients', coefficients);
  97. //>>includeEnd('debug');
  98. var normal = Cartesian2.Cartesian3.fromCartesian4(coefficients, scratchNormal);
  99. var distance = coefficients.w;
  100. //>>includeStart('debug', pragmas.debug);
  101. if (!_Math.CesiumMath.equalsEpsilon(Cartesian2.Cartesian3.magnitude(normal), 1.0, _Math.CesiumMath.EPSILON6)) {
  102. throw new Check.DeveloperError('normal must be normalized.');
  103. }
  104. //>>includeEnd('debug');
  105. if (!defined.defined(result)) {
  106. return new Plane(normal, distance);
  107. }
  108. Cartesian2.Cartesian3.clone(normal, result.normal);
  109. result.distance = distance;
  110. return result;
  111. };
  112. /**
  113. * Computes the signed shortest distance of a point to a plane.
  114. * The sign of the distance determines which side of the plane the point
  115. * is on. If the distance is positive, the point is in the half-space
  116. * in the direction of the normal; if negative, the point is in the half-space
  117. * opposite to the normal; if zero, the plane passes through the point.
  118. *
  119. * @param {Plane} plane The plane.
  120. * @param {Cartesian3} point The point.
  121. * @returns {Number} The signed shortest distance of the point to the plane.
  122. */
  123. Plane.getPointDistance = function(plane, point) {
  124. //>>includeStart('debug', pragmas.debug);
  125. Check.Check.typeOf.object('plane', plane);
  126. Check.Check.typeOf.object('point', point);
  127. //>>includeEnd('debug');
  128. return Cartesian2.Cartesian3.dot(plane.normal, point) + plane.distance;
  129. };
  130. var scratchCartesian = new Cartesian2.Cartesian3();
  131. /**
  132. * Projects a point onto the plane.
  133. * @param {Plane} plane The plane to project the point onto
  134. * @param {Cartesian3} point The point to project onto the plane
  135. * @param {Cartesian3} [result] The result point. If undefined, a new Cartesian3 will be created.
  136. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  137. */
  138. Plane.projectPointOntoPlane = function(plane, point, result) {
  139. //>>includeStart('debug', pragmas.debug);
  140. Check.Check.typeOf.object('plane', plane);
  141. Check.Check.typeOf.object('point', point);
  142. //>>includeEnd('debug');
  143. if (!defined.defined(result)) {
  144. result = new Cartesian2.Cartesian3();
  145. }
  146. // projectedPoint = point - (normal.point + scale) * normal
  147. var pointDistance = Plane.getPointDistance(plane, point);
  148. var scaledNormal = Cartesian2.Cartesian3.multiplyByScalar(plane.normal, pointDistance, scratchCartesian);
  149. return Cartesian2.Cartesian3.subtract(point, scaledNormal, result);
  150. };
  151. var scratchPosition = new Cartesian2.Cartesian3();
  152. /**
  153. * Transforms the plane by the given transformation matrix.
  154. *
  155. * @param {Plane} plane The plane.
  156. * @param {Matrix4} transform The transformation matrix.
  157. * @param {Plane} [result] The object into which to store the result.
  158. * @returns {Plane} The plane transformed by the given transformation matrix.
  159. */
  160. Plane.transform = function(plane, transform, result) {
  161. //>>includeStart('debug', pragmas.debug);
  162. Check.Check.typeOf.object('plane', plane);
  163. Check.Check.typeOf.object('transform', transform);
  164. //>>includeEnd('debug');
  165. Transforms.Matrix4.multiplyByPointAsVector(transform, plane.normal, scratchNormal);
  166. Cartesian2.Cartesian3.normalize(scratchNormal, scratchNormal);
  167. Cartesian2.Cartesian3.multiplyByScalar(plane.normal, -plane.distance, scratchPosition);
  168. Transforms.Matrix4.multiplyByPoint(transform, scratchPosition, scratchPosition);
  169. return Plane.fromPointNormal(scratchPosition, scratchNormal, result);
  170. };
  171. /**
  172. * Duplicates a Plane instance.
  173. *
  174. * @param {Plane} plane The plane to duplicate.
  175. * @param {Plane} [result] The object onto which to store the result.
  176. * @returns {Plane} The modified result parameter or a new Plane instance if one was not provided.
  177. */
  178. Plane.clone = function(plane, result) {
  179. //>>includeStart('debug', pragmas.debug);
  180. Check.Check.typeOf.object('plane', plane);
  181. //>>includeEnd('debug');
  182. if (!defined.defined(result)) {
  183. return new Plane(plane.normal, plane.distance);
  184. }
  185. Cartesian2.Cartesian3.clone(plane.normal, result.normal);
  186. result.distance = plane.distance;
  187. return result;
  188. };
  189. /**
  190. * Compares the provided Planes by normal and distance and returns
  191. * <code>true</code> if they are equal, <code>false</code> otherwise.
  192. *
  193. * @param {Plane} left The first plane.
  194. * @param {Plane} right The second plane.
  195. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  196. */
  197. Plane.equals = function(left, right) {
  198. //>>includeStart('debug', pragmas.debug);
  199. Check.Check.typeOf.object('left', left);
  200. Check.Check.typeOf.object('right', right);
  201. //>>includeEnd('debug');
  202. return (left.distance === right.distance) && Cartesian2.Cartesian3.equals(left.normal, right.normal);
  203. };
  204. /**
  205. * A constant initialized to the XY plane passing through the origin, with normal in positive Z.
  206. *
  207. * @type {Plane}
  208. * @constant
  209. */
  210. Plane.ORIGIN_XY_PLANE = freezeObject.freezeObject(new Plane(Cartesian2.Cartesian3.UNIT_Z, 0.0));
  211. /**
  212. * A constant initialized to the YZ plane passing through the origin, with normal in positive X.
  213. *
  214. * @type {Plane}
  215. * @constant
  216. */
  217. Plane.ORIGIN_YZ_PLANE = freezeObject.freezeObject(new Plane(Cartesian2.Cartesian3.UNIT_X, 0.0));
  218. /**
  219. * A constant initialized to the ZX plane passing through the origin, with normal in positive Y.
  220. *
  221. * @type {Plane}
  222. * @constant
  223. */
  224. Plane.ORIGIN_ZX_PLANE = freezeObject.freezeObject(new Plane(Cartesian2.Cartesian3.UNIT_Y, 0.0));
  225. exports.Plane = Plane;
  226. });