For certain applications, there may be an advantage from using either Cartesian
ID: 3850847 • Letter: F
Question
For certain applications, there may be an advantage from using either Cartesian coordinates (i.e. expressing position relative to the origin with the length and width of a rectangle) or polar coordinates (i.e. expressing position relative to the origin with distance and an angle). For this problem: Write two formal functions called cart2polar and polar2cart that convert between Cartesian coordinates and polar coordinates. They should be able to support vector input arguments, i.e. multiple pairs of coordinates at a time. You may use the built-in sin. cos, and atan2 functions. See the equations given below. To convert polar to Cartesian. polar2cart: x = r * cos(theta) y = r * sin(theta) To convert Cartesian to polar, cart2polar: r = Squareroot x^2 + y^2 theta = tan^-1 (y/x)Explanation / Answer
I am writing in C langauage please include "#include<math.h>" library in the top of program
cart2polar() function in c :
=> cart2polar(int x, int y){
float radius,theta;
radius=sqrt(x*x+y*y); // square root function in math.h
theta= atan(y/x); // Tan inverse function in math.h
printf("The polar coordinate values are (%f %f)",radius,theta);
}
polar2cart() function
=> polar2cart(float radius,float theta){
int x,y;
x=r*cos(theta); //cosine function in math.h
y=r*sin(theta); //sine function in math.h
printf("The cartesian form is %d+i%d)",x,y);
}
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.