Wha is this program doing?

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.

Attached: 1551046693923.jpg (966x2604, 1.57M)

Other urls found in this thread:

developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set
twitter.com/NSFWRedditGif

not doing your homework for you without something in return

lol dis nigga want the succ

And this is not homework.
I am reading about getters and setters.

developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set

Those feet are gnarly.

p,r returns the magnitude of the vector.

now go do your own homework nigger

It is clearly written in OP.
Can you read?

Attached: 1549549827906.jpg (736x736, 164K)

shut the fuck up rajesh

I'd suck that freezie.

just pay for chegg, motherfucker!

Cartesian to polar converter.

are you retarded to now understand such simple issue?

p.r is the method. it's the actual r method, nothing else.
Now invoking the method and getting its result is a different topic

Are you fucking serious right now? This is CS 101 shit. If you really can't understand this you need to switch majors

It's doing this

>>
>Jow Forums is NOT your personal tech support team or personal consumer review site.
fuck off now

Why are the posters on this board so retarded?
No one has given a proper answer yet.
You'd need to input both r and theta to find x and y.
The program should have something like:
this.x=r*Math.cos(theta);
this.y=r*Math.sin(theta);
in it.

Attached: ajq1ePg_700b.jpg (700x787, 62K)

It keeps theta from the previous result you absolute mongoloid.

this isn't even undergrad intro level, you are supposed to know what's vector and scalar multiplication already

>It keeps theta from the previous result you absolute mongoloid.
The trisomy 21 is strong with you.
theta is calculated on the spot from the values of x and y.
The way in which the program sets the values of x and y starting from r does not make sense.

Go to tutoring if you need help with your fucking home work

are you really that stupid?

Read the code again, carefully.

what the fuck are you talking about?

Change majors now, seriously, this is your last chance.

or better: consider manual work

>Read the code again, carefully.
I did.
Let's test it.
p.r=1;
console.log(p.x);
console.log(p.y);
console.log(p.theta);


This gives you

0.7071067811865475
0.7071067811865475
0.7853981633974483
.

How do you interpret these two values of x and y?

Draw the old and new coordinates on paper, realize how much of a troglodyte you are.

>programmers are easily scared

Attached: 1455837810032.png (604x613, 209K)

Can I get ONE single answer which explains what the function set r(newvalue) is doing?

Now call the change r method and check the new coordinates. Then

returns the fucking magnitude and angle of a 2D vector u cunt ass faggot bitch faggot fuck

FFS what kind of shit ugly pussy faggot beta language is that anyways

It changes r without changing theta. Holy fucking shit user, get a grip.

>get r()
pythagoreans theorum
>set r(newvalue)
scale x and y
>get theta()
calculates an angle by taking the arctan, not sure if its in degrees or radians, its ambiguous. but im guessing its in radians because its atan2 and not atan

obviously 1/sqrt(2)
can't you read that fucking code?

yes brah

//initialize some variable called oldvalue to the magnitude of the old 2D vector oldvalue=Math.sqrt(this.x*this.x+this.y*this.y);

//initialize some variable called value to be equal to the ratio between the new value which was passed to the set r function over the old value which ws just calculated
var ratio=newvalue/oldvalue;

//multiply the x and y coordinates of the 2D vector by this ratio.
this.x*=ratio;
this.y*=ratio;

Essentially this function lets u pass in a new desired magnitude for the vector, then it recalculates the new required x and y coordinates

this thread is full of retards
this

Attached: retarded1.png (219x131, 7K)

>scale x and y
Thank you so much.
This is the only answer that makes sense.
All of the others posters in this thread have shit for brains.

initialize some variable called ratio* my bad some typos in there on my phone

And what do you think scaling x and y does, retard?

I’d suck the polish off those toes.

Using the program you can find r and theta invoking the functions.
I assumed that he was somewhat trying to set value for x and y given the polar coordinates.
Now you can resize it via setting r which indeed gives you new values for x and y, but theta remains the same.
Reading that the program was doing nothing more than resizing (x,y) made me understand that my assumptions were wrong.
I doesn't go from polar to Cartesian and vice versa.

* somehow
This meant for

>Now you can resize it via setting r which indeed gives you new values for x and y, but theta remains the same.
And how many times were you told that?

After
>It changes r without changing theta. Holy fucking shit user, get a grip.
Really.
Which was the answer to my
>What does setting p.r do though?
What is that difficult answering immediately?
I was trying to figure out how he was addressing theta.

>Wha is this program doing?
throw an error if x = y = 0 and set r is used.

Looks like nobody cares what it does, kiddo.
Got another dollar? Try again kiddo

>Look mommy I'm posting on Jow Forums XD

You need to be 18 for this site, "kiddo"