CONVERT CARTESIAN COORDINATES TO POLAR COORDINATE
In mathematics, a Cartesian coordinate system is a coordinate system that specifies each point uniquely in a plane by a set of numeric points.
Cartesian Coordinates is represented by (x,y).
In mathematics, the polar coordinate system is a two-dimensional coordinate system in which each point on a plane is determined by a distance from a reference point known as radius and an angle from a reference direction known as theta or simply angle.
Polar Coordinates system is represented by (r,θ).
For the negative value of r in polar coordinates, what to do? Watch the given below youtube video to cover it.
Check this website for more knowledge: https://openstax.org/books/calculus-volume-2/pages/7-3-polar-coordinates
C++ PROGRAM :
DEFINE TWO CLASSES POLAR AND RECTANGLE REPRESENT POINTS IN POLAR AND RECTANGULAR SYSTEM. USE SUITABLE MEMBER FUNCTIONS TO CONVERT FROM ONE SYSTEM TO ANOTHER. WRITE A PROGRAM TO TEST ABOVE CLASSES.
#include <iostream>
#include <math.h>
// USING STD:: WHEN DIRECTLY IO FUNCTIONS ARE NOT WORKED.
class polar;
class rectangle
{
int x,y;
public:
rectangle(int x=0, int y=0);
polar topolar();
void display();
};
class polar{
int r,theta;
public:
polar(int r=0, int theta=0);
rectangle torectangle();
void display();
};
rectangle::rectangle(int x, int y){
this->x=x;
this->y=y;
}
polar rectangle::topolar()
{
return polar(sqrt(x*x + y*y),tan(y/x));
}
void rectangle::display()
{
std::cout<<"( "<<x<<", "<<y<<")";
}
polar::polar(int r, int theta)
{
this->r=r;
this->theta=theta;
}
rectangle polar::torectangle()
{
return rectangle(r*cos(theta), r*sin(theta));
}
void polar::display()
{
std::cout<<"( "<<r<<", "<<theta<<")";
}
int main()
{
int x, y, r, theta;
std::cout<<"Enter value in Rectangle co ordinates "<<std::endl<<"X= ";
std::cin>>x; std::cout<<"Y= "; std::cin>>y;
std::cout<<std::endl<<"Enter value in polar coordinates "<<std::endl<<"R= ";
std::cin>>r; std::cout<<"Theta= ";
std::cin>>theta;
rectangle point1(x,y);
polar point2(r,theta);
std::cout<<"Point 1: \nIn Rectangle co ordinate is: ";
point1.display();
std::cout<<"In polar co ordinate is ";
point1.topolar().display();
std::cout<<"\n\nPoint 2: \nIn Rectangle co ordinate is: ";
point2.torectangle().display();
std::cout<<"\nIn polar co-ordinate is ";
point2.display();
}
INPUT - OUTPUT :
Enter value in Rectangle co ordinates
X= 5
Y= 6
Enter value in polar coordinates
R= 5
Theta= 45
Point 1:
In Rectangle co ordinate is: ( 5, 6)In polar co ordinate is ( 7, 1)
Point 2:
In Rectangle co ordinate is: ( 2, 4)
In polar co-ordinate is ( 5, 45)
FAQ:
1> How do you convert from Polar to Rectangular?
=> To convert from Polar Coordinates (r,θ) to Cartesian Coordinates (x,y) :
x = r × cos( θ )
y = r × sin( θ )
2> How do you convert from rectangular to polar form?
=> Using Pythagoras Theorem, To convert from Cartesian Coordinates (x,y) to Polar Coordinates (r,θ).
Step 1: Square both sides of r = 5 and substitute for r^2.
r^2 = x^2 + y^2
Step 2: Determine the value of tan θ and equate this to y/ x .
tan θ = y/x
3> What is Polar and Cartesian coordinate?
Using Rectangular coordinates, or cartesian coordinates we mark a point by how far along and how far up it is.
Using Polar Coordinates we mark a point by how far away, and what angle it is.
Comments
Post a Comment