Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

math.js 928B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.checkCollinear = checkCollinear;
  6. exports.getDistance = getDistance;
  7. exports.moveTo = moveTo;
  8. function int(value) {
  9. return parseInt(value, 10);
  10. }
  11. /**
  12. * https://en.wikipedia.org/wiki/Collinearity
  13. * x=(x1+x2)/2
  14. * y=(y1+y2)/2
  15. */
  16. function checkCollinear(p0, p1, p2) {
  17. return int(p0.x + p2.x) === int(2 * p1.x) && int(p0.y + p2.y) === int(2 * p1.y);
  18. }
  19. function getDistance(p1, p2) {
  20. return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
  21. }
  22. function moveTo(to, from, radius) {
  23. var vector = { x: to.x - from.x, y: to.y - from.y };
  24. var length = Math.sqrt(vector.x * vector.x + vector.y * vector.y);
  25. var unitVector = { x: vector.x / length, y: vector.y / length };
  26. return {
  27. x: from.x + unitVector.x * radius,
  28. y: from.y + unitVector.y * radius
  29. };
  30. }
  31. //# sourceMappingURL=math.js.map