Plane3D.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import IllegalArgumentException from '../../../../java/lang/IllegalArgumentException'
  2. import Double from '../../../../java/lang/Double'
  3. import Vector3D from './Vector3D'
  4. export default class Plane3D {
  5. constructor() {
  6. Plane3D.constructor_.apply(this, arguments)
  7. }
  8. static constructor_() {
  9. this._normal = null
  10. this._basePt = null
  11. const normal = arguments[0], basePt = arguments[1]
  12. this._normal = normal
  13. this._basePt = basePt
  14. }
  15. closestAxisPlane() {
  16. const xmag = Math.abs(this._normal.getX())
  17. const ymag = Math.abs(this._normal.getY())
  18. const zmag = Math.abs(this._normal.getZ())
  19. if (xmag > ymag)
  20. if (xmag > zmag) return Plane3D.YZ_PLANE; else return Plane3D.XY_PLANE
  21. else if (zmag > ymag)
  22. return Plane3D.XY_PLANE
  23. return Plane3D.XZ_PLANE
  24. }
  25. orientedDistance(p) {
  26. const pb = new Vector3D(p, this._basePt)
  27. const pbdDotNormal = pb.dot(this._normal)
  28. if (Double.isNaN(pbdDotNormal)) throw new IllegalArgumentException('3D Coordinate has NaN ordinate')
  29. const d = pbdDotNormal / this._normal.length()
  30. return d
  31. }
  32. }
  33. Plane3D.XY_PLANE = 1
  34. Plane3D.YZ_PLANE = 2
  35. Plane3D.XZ_PLANE = 3