1. Re: polar to rectangular conversion

>> Does anyone know how to calculate a new position from on old when
>> you have an angle (360 degrees, no radians) and a distance?

> global constant pi = 3.141592654
>
> function Deg2Rad(atom deg) -- convert degree to radian
>   return deg/180*pi
> end function
>
> function Rad2Deg(atom radian)
>    return radian/pi*180
> end function
>
> function Polar2Rect(atom angle, atom distance) -- convert polar to rectangular
> -- angle is in degree

atom x,y

>    x = cos(Deg2Rad(angle)*distance
>    y = sin(Deg2Rad(angle)*distance
>    return {x,y}
> end function
>
> function Rect2Polar(atom dx, atom dy) -- convert rectangular to polar
> -- dx and dy are delta x and y between to points (or to the origin)
> atom distance, angle
>--   distance = sqrt(x*x + y*y)

  distance = sqrt(dx*dx + dy*dy)

>   angle = Rad2Deg(arctan(dy/dx)

-- Whoa! Easy! You're assuming dx!=0, dx>=0, dy>=0. Or, in other words, that
-- 0<angle<90 (deg)... try this:

  if dx=0 then return({sgn(dy)*90,distance}) end if
  angle = remainder(360+Rad2Deg(arctan(dy/dx))+(dx<0)*180,360)

-- If anyone knows how to simplify it, feel free. (Trig. *SUCKS*!!)

>   return {angle,distance}
> end function
>

>> Ralf
> Jacques Deschenes
Anders

PS. Don't take my word for it. Test it, I might have copied it wrong or
something...
--------------------------------------------------------------
Anders Eurenius <c96aes at cs.umu.se> ICQ UIN:1453793
Computer Science/Engineering student at the university of Umea
--------------------------------------------------------------

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu