java - Realistic Bounce of Ball (off Line) in Coordinate Grid -


the problem

so i'm trying make program makes ball bounce off of line calculating angle ball make line -- if intersecting line -- , rotating line around intersection point find new slope. have algorithms , formulas except part hand slope ball momentum. end product of calculations (which have made sure work) slope of line , intersection, or bounce, point. if have slope, how able tell direction ball traveling on slope, after bounce?

sidenote : language working in java 1.8 arbitrary external graphics library, i'm not looking code plug in preexisting code, i'm looking general idea of think might able do. also, critical problem, entire project coordinate-based.

thanks lot input or possible answer, , ask me if specifications on problem!

www.cwynn.com/bounce little html5 canvas thing made few years ago illustrates how op wanting handle 'bounce'

you have ball b, hit line l on collision point c. b->c makes line. take point on line beyond c , reflect across l reflection point r. when ball hits c can delete it's direction vector, , give vector of c->r. need reset speed though. grab size of direction vector, , scale new direction vector match.

edit: decided add code (which made me realize forgot scaling speed)

    //closestcollpt[0] line 'player' hit next     var dist = player.position.dist(closestcollpt[0]);      //the 'player' in case circle, indicates collision     if(dist < player.radius*2)     {         //the collision point reflection mentioned         //in text above         var newdir = closestcollpt[0].vecto(reflection);          //i break out parts, b/c want scale vector         //doable in 1 line, hard debug         var newdirx = newdir.x;         var newdiry = newdir.y;         var newdirdist = newdir.dist(new vector(0,0));         //for whatever reason calling size of vector         //'dist' when wrote           var currdirdist = player.direction.dist(new vector(0,0));          //give player direction got coll->ref         //scale speed doesn't change         player.direction = newdir.scale(currdirdist).scale(1/newdirdist);     } 

decided add image...

the 'real' things ball , brown line

the 'ball' pink, headed towards 'contact' point in center on ray 'path',

projection reflection of ball across contact point, , reflection reflection of projection point across line.

once ball contacts brown line it's direction vector should change 'path' 'new path' (line sits on contact , reflection)

enter image description here


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -