
rectangular to polar coordinate and inverse tangent function
I'm creating a lab for my trig classes where they use sliders to transform the x and y coordinates of a point to the polar coordinates. Everything works fine as long as (x, y) is in one of the quadrants, but if the point is on either axis, it doesn't work. Here's my code.
Q1: arctan(y/x) * (((1 + sgn(x))/2) * (((1 + sgn(y))/2) * (abs(sgn(y*x)))
Q2: arctan(y/x) * (((1  sgn(x))/2) * (((1 + sgn(y))/2) * (abs(sgn(y*x)))
Q3: arctan(y/x) * (((1  sgn(x))/2) * (((1  sgn(y))/2) * (abs(sgn(y*x)))
Q4: arctan(y/x) * (((1 + sgn(x))/2) * (((1  sgn(y))/2) * (abs(sgn(y*x)))
I added the "abs(sgn" expressions to eliminate errors with points on the axes. Summing the four expressions gives correct values for theta as long as they are in the quadrants? Any suggestions as to how I can make it work on the axes as well. Do I need to create a unique function for that as well?

Rectangular to Polar
Hi Mr. H,
I'd like to make two suggestions, and offer some other thoughts about this interesting problem.
(1) Although the signum function is that basis of making decisions about whether values are greater than, equal to, or less than other values, I have trouble using sgn(x) directly, as in calculations like yours. I find I have to stop and figure out what the results are for positive, zero, or negative values of x. I much prefer using the Boolean Tools, and I've just posted an updated set of those tools.
(2) I like your clever approach of doing a separate calculation for each quadrant, adjusting each calculation to give 0 for the three quadrants in which it does not apply, and then adding the four calculations. The biggest difficulty of such an approach is handling the boundary cases: points on the axes. This is where the Boolean tools may come in particularly handy for you, because using (for instance) the x<0 tool and the x>=0 tool cleanly assigns the boundary to the x>=0 case.
You may even find that the tools give you the power to use a single calculation. For instance, Arctan(y/x) + 180° * (x<0) gives you a correct value for both quadrants 1 and 2; with a bit more work you may be able to accommodate all four quadrant in a single calculation. (I won't spoil the challenge by posting a proposed solution here, and I encourage anyone who does post their solution to include "SPOILER" in the title of their post.)
Finally, I assume you are doing this as an exercise for your students, and don't want Sketchpad to do the work for you. At some point, you may want to observe to students that there are at least three ways to get Sketchpad to do it for you: (a) Change the Grid Form to Polar, measure the value of theta for the point, and then change the Grid Form back to Square. (b) Construct a ray from the origin through the unit point and a segment from the origin to the point being measured. Then create and measure a counterclockwise angle marker from the positive xaxis (the ray) to the segment. (c) Construct a circle centered at the origin and passing through the point to be measured. Select the circle, its intersection with the positive xaxis, and the point to be measured, and choose Construct  Arc on Circle. With the arc selected, measure the Arc Angle. Students may further be interested to know that Sketchpad itself also uses calculations very like those proposed in your original post to create the measurements it displays when you use method (a), (b), or (c) above.
Happy sketching,
Scott

Thanks for the insight. I've never used Booleans in sketches before. I guess now will be the time to learn. I'm flipping the class and am creating problems for them to solve at home as practice. We'll discuss the concepts in class when they return and use suggestions like those in your final paragraph. Again, thanks for the reply. I got tired of beating my head in the wall.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts
Forum Rules