pastebin - collaborative debugging tool
blankb.kpaste.net RSS


Cartesian to Polar Processing.org
Posted by Anonymous on Sat 14th Jan 2012 15:24
raw | new post

  1. class Polar
  2. {
  3.   float deg;
  4.   float radius;
  5. }
  6. class Cartesian
  7. {
  8.   float x;
  9.   float y;
  10. }
  11. Cartesian polarToCartesian(float deg,float pradius)
  12. {
  13.   Cartesian cartesianval=new Cartesian();
  14.   deg=deg-90;
  15.    
  16.   cartesianval.x = cos(radians(deg))*pradius;
  17.   cartesianval.y = sin(radians(deg))*pradius;
  18.  
  19.   return cartesianval;
  20. }
  21. Polar cartesianToPolar(float x, float y)
  22. {
  23.   Polar polarVal=new Polar();
  24.   polarVal.deg=degrees(atan2(x,y));
  25.   if (polarVal.deg<0) { polarVal.deg=360+polarVal.deg; }
  26.   polarVal.radius=sqrt( (x*x)+(y*y));
  27.   return polarVal;
  28. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at