Admiral_Damage

Untitled

Apr 2nd, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculatePolar(){
  2.     var x = $F('x');
  3.     var y = $F('y');
  4.     var r = Math.pow((Math.pow(x,2) + Math.pow(y,2)),0.5);
  5.     var theta = Math.atan(y/x)*360/2/Math.PI;
  6.     if (x >= 0 && y >= 0) {
  7.         theta = theta;
  8.     } else if (x < 0 && y >= 0) {
  9.         theta = 180 + theta;
  10.     } else if (x < 0 && y < 0) {
  11.         theta = 180 + theta;
  12.     } else if (x > 0 && y < 0) {
  13.         theta = 360 + theta;
  14.     }
  15.  
  16.     //Box.ajaxReq('/docs/scripts/conv.js',false);
  17.     var msg = ""
  18.         + "Polar Coordinates (" + Conv.rounding(r) + ", " + Conv.rounding(theta) + ")\n"
  19.         + "";
  20.     alert(msg);    
  21. }
  22.  
  23. function calculateCartesian(){
  24.     var r = $F('r');
  25.     var theta = $F('theta');
  26.     var x = r * Math.cos(theta * 2 * Math.PI / 360);
  27.     var y = r * Math.sin(theta * 2 * Math.PI / 360);
  28.     //Box.ajaxReq('/docs/scripts/conv.js',false);
  29.     var msg = ""
  30.         + "Cartesian Coordinates (" + Conv.rounding(x) + ", " + Conv.rounding(y) + ")\n"
  31.         + "";
  32.     alert(msg);    
  33. }
Advertisement
Add Comment
Please, Sign In to add comment