RedKnight91

pivot_point

Feb 10th, 2019
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. ///@func pivot_point()
  2. ///@desc Given an 'origin' point, pivot another point around it.
  3. /// Takes in origin point coordinates, pivoting point distance (relative = true) or absolute coordinates (relative = false)
  4. /// Returns an [x,y] array with the pivoted point coordinates
  5. ///
  6. ///@param origin_x Origin X
  7. ///@param origin_y Origin Y
  8. ///@param point_x Point X distance or X coordinate
  9. ///@param point_y Point Y distance or Y coordinate
  10. ///@param relative [Boolean] Point is passed as distance from origin (true) or absolute coordinates (false)
  11. ///@param pivot_angle The angle at which the point is to be pivoted
  12.  
  13. var _origin_x = argument0;
  14. var _origin_y = argument1;
  15. var _point_x = argument2;
  16. var _point_y = argument3;
  17. var _relative = argument4;
  18. var _pivot_angle= argument5;
  19.  
  20. //Find the origin-to-point angular distance
  21. var _dist = _relative ? point_distance(0, 0, _point_x, _point_y) : point_distance(_origin_x, _origin_y, _point_x, _point_y);
  22.  
  23. //Find the origin-to-point angle, plus pivot
  24. var _angle = _relative ? point_direction(0, 0, _point_x, _point_y) : point_direction(_origin_x, _origin_y, _point_x, _point_y)
  25. _angle += _pivot_angle;
  26.  
  27. var _x = _origin_x + lengthdir_x(_dist, _angle); //Get the pivoted origin-to-point x distance
  28. var _y = _origin_y + lengthdir_y(_dist, _angle); //Get the pivoted origin-to-point y distance
  29.  
  30. return [_x, _y]; //return coordinates as an array
Advertisement
Add Comment
Please, Sign In to add comment