python - Ball-Line Segment Collision on End-Point of Line -


so have program ball subject gravity bounces off of lines created user mouse clicks. these lines sloped. collision bounces work except in case ball approximately this: ->o ------

my code works finding normal vector of line such scalar product of incident velocity vec of ball , normal of line negative (this means vector have opposite directions). decompose velocity terms parallel , perpendicular normal, , reverse direction of parallel component.

during edge case described above ball moves along line. how can account this? advice?>

possible solutions:

  1. instead of using single 1d 'line', construct 2d rectangle (that want/need be) --- composed of 4 separate 'lines'. i.e. can have collisions of 4 faces of rectangle object. work?
  2. do sort of corner collision -- if ball 'hits' start or end of line, have bounce off appropriately. think way done follows:
    i. collision occurs if corner falls within radius of ball.
    ii. define line between corner , center of ball.
    iii. reverse component of ball's velocity along line.

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -