Beam.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import VectorType from '../enum/VectorType.js'
  2. import SelectState from '../enum/SelectState.js'
  3. import Geometry from './Geometry'
  4. import { mathUtil } from '../MathUtil.js'
  5. import Constant from '../Constant.js'
  6. import { coordinate } from '../Coordinate'
  7. //靠墙
  8. export default class Beam extends Geometry {
  9. constructor(center, vectorId) {
  10. super()
  11. this.center = center
  12. this.angle = 0 //逆时针为负,顺时针为正。单位是:°
  13. this.points2d = []
  14. this.sideWidth = 0.65
  15. this.sideThickness = 0.65
  16. this.name = '柱子'
  17. this.geoType = VectorType.Beam
  18. this.setId(vectorId)
  19. }
  20. isContain(position) {
  21. return mathUtil.isPointInPoly(position, this.points2d)
  22. }
  23. setPoints2d() {
  24. this.points2d = []
  25. const minX = this.center.x - this.sideWidth / 2
  26. const minY = this.center.y - this.sideThickness / 2
  27. const maxX = this.center.x + this.sideWidth / 2
  28. const maxY = this.center.y + this.sideThickness / 2
  29. const point1 = this.rotatePoint(
  30. {
  31. x: minX,
  32. y: maxY,
  33. },
  34. this.center,
  35. this.angle
  36. )
  37. const point2 = this.rotatePoint(
  38. {
  39. x: maxX,
  40. y: maxY,
  41. },
  42. this.center,
  43. this.angle
  44. )
  45. const point3 = this.rotatePoint(
  46. {
  47. x: maxX,
  48. y: minY,
  49. },
  50. this.center,
  51. this.angle
  52. )
  53. const point4 = this.rotatePoint(
  54. {
  55. x: minX,
  56. y: minY,
  57. },
  58. this.center,
  59. this.angle
  60. )
  61. this.points2d.push(point1)
  62. this.points2d.push(point2)
  63. this.points2d.push(point3)
  64. this.points2d.push(point4)
  65. }
  66. }