Write a function named \"XYtoPolar\" that has 2 double value parameters and 2 do
ID: 3550979 • Letter: W
Question
- Write a function named "XYtoPolar" that has 2 double value parameters and 2 double reference parameters that converts x,y coordinates to polar coordinates. The prototype is: void XYtoPolar(double x, double y, double* angle, double* radius); Look up in a math book or on the Internet how to do the conversion mathematically and code that into your program. The effect of the function is to take arbitrary values for x and y representing the coordinates of a point on the x,y plane and sets the variables pointed to by angle and radius to the corresponding polar coordinates of the same point, with the angle in radians, not degrees. For example, the point x=1, y=1 has polar coordinates angle=0.785398163, radius = 1.41421356237. Hint: the C math function atan(x) returns the inverse tangent of x.
Explanation / Answer
void XYtoPolar(double x, double y, double* angle, double* radius) {
radius = sqrt(pow(x,2)+pow(y,2));
angle = atan(y/x);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.