Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-01-18 20:25:48
  4. */
  5. class Vector {
  6. constructor(u, v) {
  7. this.u = u
  8. this.v = v
  9. this.m = this.magnitude()
  10. }
  11. /**
  12. * the vector value
  13. * @returns {Number}
  14. */
  15. magnitude() {
  16. return Math.sqrt(this.u * this.u + this.v * this.v)
  17. }
  18. /**
  19. * Angle in degrees (0 to 360º) --> Towards
  20. * N is 0º and E is 90º
  21. * @returns {Number}
  22. */
  23. directionTo() {
  24. let verticalAngle = Math.atan2(this.u, this.v)
  25. let inDegrees = verticalAngle * (180.0 / Math.PI)
  26. if (inDegrees < 0) {
  27. inDegrees += 360.0
  28. }
  29. return inDegrees
  30. }
  31. /**
  32. * Angle in degrees (0 to 360º) From x-->
  33. * N is 0º and E is 90º
  34. * @returns {Number}
  35. */
  36. directionFrom() {
  37. let a = this.directionTo()
  38. return (a + 180.0) % 360.0
  39. }
  40. }
  41. export default Vector