Re: New proposal for math.e
- Posted by Juergen Luethje <j.lue at ??x.de> Aug 04, 2007
- 520 views
Colin Taylor wrote: <snip> > I would also like to add a couple of functions: > > }}} <eucode> > > global function polar_to_rect(sequence xy) > -- convert a rectangular coordinates to polar coordinates > atom angle, distance, x, y > x = xy[1] > y = xy[2] > distance = sqrt(power(x, 2)+power(y, 2)) > if x > 0 then > angle = arctan(y/x) > elsif x < 0 then > if y < 0 then > angle = arctan(y/x)-PI > else > angle = arctan(y/x)+PI > end if > else > if y < 0 then > angle = -HALF_PI > else > angle = HALF_PI > end if > end if > return {distance, angle} > end function > > global function rect_to_polar(sequence pol) > -- convert a polar coordinates to rectangular coordinates > atom distance, angle, x, y > distance = pol[1] > angle = pol[2] > x = distance*cos(angle) > y = distance*sin(angle) > return {x, y} > end function > > </eucode> {{{ > > In the above functions, angle is expressed in radians, increasing in a > clockwise > direction from east. > > Regards, Colin (now returning to deep lurk mode) I don't know what you mean by "east" in this context. However, the normal math convention is: Increasing positive values of an angle correspond to _counter_ clockwise rotation. But I've seen now that different textbooks use different conventions about the range of values that is used for the angle in Polar Coordinates. Some books use -PI < a <= PI, while others use 0 <= a < 2*PI. Our implementation of the functions will depend on the range that we'll allow for the angle. Regards, Juergen