Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Mathematical Functions : atan2

atan2

Arc tangent of two variables (PHP 4, PHP 5)
float atan2 ( float y, float x )


Code Examples / Notes » atan2

reubs

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. :)


monte shaffer

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);
}


Change Language


Follow Navioo On Twitter
abs
acos
acosh
asin
asinh
atan2
atan
atanh
base_convert
bindec
ceil
cos
cosh
decbin
dechex
decoct
deg2rad
exp
expm1
floor
fmod
getrandmax
hexdec
hypot
is_finite
is_infinite
is_nan
lcg_value
log10
log1p
log
max
min
mt_getrandmax
mt_rand
mt_srand
octdec
pi
pow
rad2deg
rand
round
sin
sinh
sqrt
srand
tan
tanh
eXTReMe Tracker