collision-detection

Circle line-segment collision detection algorithm?

吃可爱长大的小学妹 提交于 2019-11-25 23:09:03
问题 I have a line from A to B and a circle positioned at C with the radius R. What is a good algorithm to use to check whether the line intersects the circle? And at what coordinate along the circles edge it occurred? 回答1: Taking E is the starting point of the ray, L is the end point of the ray, C is the center of sphere you're testing against r is the radius of that sphere Compute: d = L - E ( Direction vector of ray, from start to end ) f = E - C ( Vector from center sphere to ray start ) Then

jQuery/JavaScript collision detection

风流意气都作罢 提交于 2019-11-25 23:05:15
问题 How to detect if two <div> elements have collided? The two divs are simple coloured boxes travelling perpendicular to each other, so no complicated shapes or angles. 回答1: var overlaps = (function () { function getPositions( elem ) { var pos, width, height; pos = $( elem ).position(); width = $( elem ).width(); height = $( elem ).height(); return [ [ pos.left, pos.left + width ], [ pos.top, pos.top + height ] ]; } function comparePositions( p1, p2 ) { var r1, r2; r1 = p1[0] < p2[0] ? p1 : p2;

Circle-Rectangle collision detection (intersection)

懵懂的女人 提交于 2019-11-25 22:59:20
问题 How can I tell whether a circle and a rectangle intersect in 2D Euclidean space? (i.e. classic 2D geometry) 回答1: There are only two cases when the circle intersects with the rectangle: Either the circle's centre lies inside the rectangle, or One of the edges of the rectangle has a point in the circle. Note that this does not require the rectangle to be axis-parallel. (One way to see this: if none of the edges has a point in the circle (if all the edges are completely "outside" the circle),

Ball to Ball Collision - Detection and Handling

最后都变了- 提交于 2019-11-25 22:43:21
问题 With the help of the Stack Overflow community I\'ve written a pretty basic-but fun physics simulator. You click and drag the mouse to launch a ball. It will bounce around and eventually stop on the \"floor\". My next big feature I want to add in is ball to ball collision. The ball\'s movement is broken up into a x and y speed vector. I have gravity (small reduction of the y vector each step), I have friction (small reduction of both vectors each collision with a wall). The balls honestly move