Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--============================================================================================================//
- //--====||||||||||||====||||||||||====|===========||||||||||=====|============|======|||||||||||=====|==========//
- //--====|===============|========|====|===========|========|=====|=\==========|======|===============|==========//
- //--====|===============|========|====|===========|========|=====|===\========|======|===============|==========//
- //--====|===============|========|====|===========|========|=====|====\=======|======|===============|==========//
- //--====|===============|========|====|===========|========|=====|=====\======|======|===============|==========//
- //--====|===============|========|====|===========|========|=====|=====\======|======|||||||||||=====|==========//
- //--====|===============|========|====|===========|========|=====|======\=====|======|===============|==========//
- //--====|===============|========|====|===========|========|=====|=======\====|======|===============|==========//
- //--====|===============|========|====|===========|========|=====|=======\====|======|===============|==========//
- //--====|===============|========|====|===========|========|=====|========\===|======|===============|==========//
- //--====||||||||||||====||||||||||====|||||||||===||||||||||=====|==========\=|======|||||||||||=====||||||||===//
- //--============================================================================================================//
- //--============================================================================================================//
- /*
- Code by : Promsurin Phutthammawong
- ID: 5910613313
- Task : Polar-Cart.c
- Date Submit : 7/11/2016
- */
- //////////////--- Call header files --- /////////////
- #include <stdio.h> // Include standard input output function header
- #include <math.h> // Include math function header
- #define pi 3.1415926535897932384626433832795 ///// Define PI VALUE
- /////////////// Declare Functions //////////////////
- void pol2cart (double r , double theta);
- // /\ | Variable in function |
- // |
- // Function name //
- void cart2pol (double x, double y);
- // /\ | Variable in function |
- // |
- // Function name //
- ////////////// Declare Global Variable for using entire code //////////////
- double r1=0,theta1=0; // Because its must be use all section in code
- double x1 = 0 , y1 = 0 ; /// Give default Value when declare = 0 prevent bug;
- // Main Code //
- int main()
- {
- printf("Enter x: "); /// Printf ...
- scanf("%lf",&x1); /// Scanf ...
- printf("Enter y: "); /// print ...
- scanf("%lf",&y1); /// scanf ...
- cart2pol(x1,y1); /// Call function cart2pol and now its working on (*) symbols find it in code
- ////////This x1 and y1 will be placed in ***cart2pol ( double x , double y)***
- printf("Change to Polar coordinates: (%.2f,%.2f)\n",r1,theta1);
- pol2cart(r1,theta1); /// Call function pol2cart and now its working on (**) symbols find it in code
- ////////This r1 and thta1 will be placed in ***cart2pol ( double r , double theta)***
- printf("Change to Cartesian coordinates: (%.2f,%.2f)\n",x1,y1);
- return 0;
- }
- ////////// End main //////////////
- /////// Function pol2cart ////////
- void pol2cart ( double r , double theta) // (**)
- {
- theta = theta*pi/180; /// Theta is degree so we change it in to radian
- x1 = r*cos(theta); /// Calculate
- y1 = r*sin(theta); /// Calculate
- // End function continue on main
- }
- /////// Function cart2pol ////////
- void cart2pol ( double x , double y) // (*)
- {
- r1 = sqrt(pow(x,2)+pow(y,2)); /// Calculate
- theta1 = atan(y/x); /// Calculate
- theta1 = theta1*180/pi;
- /// start quadrant check
- if(x == 0 && y == 0) /// if Theta x y = 0;
- theta1= 0;
- if(x > 0 && y > 0)
- theta1 = theta1; /// Check Quadrant
- else if(x > 0 && y < 0)
- theta1 -= 180;
- else if(x < 0 && y < 0)
- theta1 -= 180;
- else if( x < 0 && y > 0)
- theta1 += 180;
- /// End if
- if ( theta1 > 180) /// if more than 180 substact it
- theta1 -= 180;
- else if ( theta1 < -180) /// if less than -180 plus it
- theta1 += 180;
- /// End if
- /// End function continue on main
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement