Difference between revisions of "findRotation"

m (Added missing property for the category page, edited credits to format used elsewhere.)
 
Line 1: Line 1:
 
This function takes two sets of XY coordinates. It returns the direction from point A to point B.  
 
This function takes two sets of XY coordinates. It returns the direction from point A to point B.  
 
'''Original function by Doomed_Space_Marine. Fixed, tested by robhol.  Wikified by qaisjp.'''
 
  
 
==Syntax==
 
==Syntax==
Line 23: Line 21:
  
 
[[Category:Snippets]]
 
[[Category:Snippets]]
{{#set:Author=Doomed_Space_Marine, robhol}}
+
{{#set:Author=Doomed_Space_Marine, robhol, qaisjp}}
 +
{{#set:LOVE Version=any}}
 
{{#set:Description=Takes two points and returns the direction from point A to point B.}}
 
{{#set:Description=Takes two points and returns the direction from point A to point B.}}

Latest revision as of 00:35, 12 November 2016

This function takes two sets of XY coordinates. It returns the direction from point A to point B.

Syntax

float findRotation(float Xa, float Ya, float Xb, float Yb)

Required Arguments

  • Xa: The X coordinate of the starting point.
  • Ya: The Y coordinate of the starting point.
  • Xb: The X coordinate of the target point.
  • Yb: The Y coordinate of the target point.

Source

function findRotation(x1,y1,x2,y2)
 
  local t = -math.deg(math.atan2(x2-x1,y2-y1))
  if t < 0 then t = t + 360 end;
  return t;
 
end