Create a user defined unction that will convert a coordinate (x, y) in the Carte
ID: 3860116 • Letter: C
Question
Create a user defined unction that will convert a coordinate (x, y) in the Cartesian coordinate System to a polar coordinate (r, theta) where theta is in radius, referenced positive counter clockwise from the x-axis. Use the function definition line function (r, th) = cart2polar(x, y) in your solution. Keep in mind that there are four quadrants in the Cartesian system and the traditional sine and cosine functions only provide the first quadrant value. Assume only scalar values will be sent to the function.Explanation / Answer
void cart2polar(double x, double y)
{
const double ToDegress = 180.0/3.141593; // Defined to convert Radians to Degrees
r = sqrt(x*x + y*y);
theta = atan(y/x) * ToDegress;
x[0]=r;
x[1]=theta;
return x;
}
This is the function which can convert cartesian to polar. you can use the line gives in main function after taking coordinates x and y as input
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.