Skip to content

Instantly share code, notes, and snippets.

@eoghanmcilwaine
Created April 12, 2012 23:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eoghanmcilwaine/2371915 to your computer and use it in GitHub Desktop.
Save eoghanmcilwaine/2371915 to your computer and use it in GitHub Desktop.
PHP function to get a point from given origin point, angle and distance
/**
* Get a point <var>dist</var> units away from <var>$cx</var>,<var>$cy</var>
* on angle <var>$ang</var>.
*
* @param {number} $cx The x coordinate of the origin point.
* @param {number} $cy The y coordinate of the origin point.
* @param {number} $ang Angle from the origin point to the returned point, in degrees.
* @param {number} $dist Unit distance from the origin point to the returned point.
* @return {array} x and y coordinates of the return point.
*/
public function getPoint($cx, $cy, $ang, $dist)
{
// Convert angle from degrees to radians
$ang = deg2rad($ang);
$x = $cx + ($dist * (cos($ang)));
$y = $cy + ($dist * (sin($ang)));
return array($x, $y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment