var p={
x:1.0,
y:1.0,
get r(){
return Math.sqrt(this.x*this.x+this.y*this.y);
},
set r(newvalue){
var oldvalue=Math.sqrt(this.x*this.x+this.y*this.y);
var ratio=newvalue/oldvalue;
this.x*=ratio;
this.y*=ratio;
},
get theta(){
return Math.atan2(this.y, this.x);
}
};
I do know what polar coordinates are.
p.r returns the distance between (1,1) and (0,0) which is Math.sqrt(2).
Math.atan2 returns the angle.
What does setting p.r do though?
I can follow the math on paper but I don't understand the logic behind it.
This is JavaScript.