note 47469 added to ref.math

From: Date: Wed, 17 Nov 2004 12:34:45 +0000
Subject: note 47469 added to ref.math
Groups: php.notes 
Request: Send a blank email to php-notes+get-80635@lists.php.net to get a copy of this message
If you need to deal with polar co-ordinates for somereason you will need to convert to and from x,y for input and output in most situations: here are some functions to convert cartesian to polar and polar to cartesian <? //returns array of r, theta in the range of 0-2*pi (in radians) function rect2polar($x,$y) { if(is_numeric($x)&&is_numeric($y)) { $r=sqrt(pow($x,2)+pow($y,2)); if($x==0) { if($y>0) $theta=pi()/2; else $theta=3*pi()/2; } else if($x<0) $theta=atan($y/$x)+pi(); else if($y<0) $theta=atan($y/$x)+2*pi(); else $theta=atan($y/$x); $polar=array("r"=>$r,"theta"=>$theta); return $polar; } else return false; } //r must be in radians, returns array of x,y function polar2rect($r,$theta) { if(is_numeric($r)&&is_numeric($theta)) { $x=$r*cos($theta); $y=$r*sin($theta); $rect=array("x"=>$x,"y"=>$y); } else { return false; } } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.math.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47469 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47469&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47469&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47469&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47469&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47469&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47469&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47469&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80635) next »