javascript - Inelastic collision only moving object to the right -


my rocket hitting inertia object, defined in handlecollision. i'm passing in rocket has .r value theta , .power magnitude.

i'm wanting update .rotation & .magnitude according inelastic collision defined wikipedia

when colliding left, inertia moves right.

but when colliding right errors , moves 180 degrees off. if rocket , right @ 45 degree angle inertia object, object move , right @ 45 degree angle.

what missing here? thought might issue atan function converted y component & x component of vector radians first, same issue.

handlecollision(rocket) {     var angle = rocket.r * math.pi / 180.0;     var rr = this.rotation * math.pi / 180;      var rocketvector = {'x' : r.power * math.cos(angle), 'y' : r.power * math.sin(angle)};     var inertiavector = {'x' : this.magnitude * math.cos(rr), 'y' : this.magnitude * math.sin(rr)};      var rmass = 10;     var shipmass = 10;      var x = (rmass * rocketvector.x) + (shipmass * inertiavector.x);     var y = (rmass * rocketvector.y) + (shipmass * inertiavector.y);     var xdividedbymass = x / (rmass + shipmass);     var ydividedbymass = y / (rmass + shipmass);      var yradians = (ydividedbymass * math.pi / 180);     var xradians = (xdividedbymass * math.pi / 180);     var theta = math.atan( yradians / xradians);      theta = theta * 180 / math.pi;     console.log(theta);      var hypotenuse = math.sqrt((xdividedbymass * xdividedbymass) + (ydividedbymass * ydividedbymass));     this.magnitude = hypotenuse;     this.rotation = theta;     if (this.rotation < 0) {         this.rotation += 360;     } else if (this.rotation > 360) {         this.rotation -= 360;     } } 

if xdividedbymass>0, great because quadrant or iv arctangent kicks out values. if not negative angle, okay add 360 did. if x<0 , y>0, negative angle , want add 180 q ii (tangent has period of 180). , if x<0, , y<0, in qiii , again arctan gives in q1 must add 180. logic this.

if ((x > 0) && (y<0)) {     this.rotation += 360; } else if (x<0) {     this.rotation += 180; } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -