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 766B

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