Created
April 12, 2012 23:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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