Re: Proposal for 'math.e' (2007-08-07)
- Posted by Colin Taylor <colinetaylor at ?mail.?om> Aug 07, 2007
- 510 views
Juergen Luethje wrote: > > This is my current (2007-08-07) proposal for a "math.e" standard > include file, according to the recent discussion here on EUforum. > ... > > type point_pol (object x) > if sequence(x) and (length(x) = 2) > and atom(x[1]) and (x[1] >= 0) > and atom(x[2]) then > return 1 > end if > return 0 > end type > > global function polar_to_rect (point_pol p) > -- convert polar coordinates to rectangular coordinates > -- in : sequence of two atoms: {distance, angle}; > -- 'distance' must be >= 0, 'angle' is in radians > -- out: sequence of two atoms: {x, y} > atom distance, angle, x, y > > distance = p[1] > angle = p[2] > x = distance*cos(angle) > y = distance*sin(angle) > return {x, y} > end function > > type point_xy (object x) > if sequence(x) and (length(x) = 2) > and atom(x[1]) > and atom(x[2]) then > return 1 > end if > return 0 > end type > > global function rect_to_polar (point_xy p) > -- convert rectangular coordinates to polar coordinates > -- in : sequence of two atoms: {x, y} > -- out: sequence of two elements: {distance, angle} > -- - 'distance' is always an atom >= 0 > -- - 'angle' is normally an atom that expresses radians, > -- and is in the half-closed interval ]-PI,+PI]. > -- If 'distance' equals 0, then 'angle' is {}, > -- meaning that it is undefined in this case. > object angle > atom distance, x, y > > x = p[1] > y = p[2] > distance = sqrt(x*x + y*y) > 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 > elsif y > 0 then > angle = HALF_PI > else > angle = {} -- The angle is undefined in this case. > end if > end if > return {distance, angle} > end function > ... > > Regards, > Juergen Hi Juergen, I disagree with your solution to the special case rect_to_polar({0,0}). By setting the undefined angle to {}, you create a situation where the result cannot be translated back to rectangular coordinates. You are creating a real problem in order to solve what (imho) is an imagined problem. Regards, Colin