Here is a function that will return a new point [Rotate around non-origin pivot point]
(x,y) is current point
(cx,cy) is pivot point to rotate
=a= is angle in degrees
$_rotation = 1; # -1 = counter, 1 = clockwise
$_precision = 2; # two decimal places
function returnRotatedPoint($x,$y,$cx,$cy,$a)
{
# http://mathforum.org/library/drmath/view/63184.html
global $_rotation; # -1 = counter, 1 = clockwise
global $_precision; # two decimal places
// radius using distance formula
$r = sqrt(pow(($x-$cx),2)+pow(($y-$cy),2));
// initial angle in relation to center
$iA = $_rotation * rad2deg(atan2(($y-$cy),($x-$cx)));
$nx = number_format($r * cos(deg2rad($_rotation * $a + $iA)),$_precision);
$ny = number_format($r * sin(deg2rad($_rotation * $a + $iA)),$_precision);
return array("x"=>$cx+$nx,"y"=>$cy+$ny);
}
atan2
(PHP 4, PHP 5)
atan2 — Arc tangent of two variables
Description
float atan2
( float $y
, float $x
)
This function calculates the arc tangent of the two variables x and y . It is similar to calculating the arc tangent of y / x , except that the signs of both arguments are used to determine the quadrant of the result.
The function returns the result in radians, which is between -PI and PI (inclusive).
Parameters
- y
-
Dividend parameter
- x
-
Divisor parameter
Return Values
The arc tangent of y /x in radians.
atan2
Monte Shaffer
08-Jun-2007 02:35
08-Jun-2007 02:35
reubs at idsdatanet dot com
23-May-2003 04:01
23-May-2003 04:01
Just a note:
PHP's atan2 function receives parameters in (y,x) and Excel receives it in (x,y) format. Just in case you are porting formulas across. :)
