collision

Sphere - sphere collision detection -> reaction

孤街醉人 提交于 2019-11-30 21:06:28
I need to make an algorithm that detects when two spheres collide, and, the direction that wich one will take an instant after the collision. Let say, Imagine like when you open your table in a pool match, all the balls are colliding one to another "randomly". So, before starting to write the code myself, I was thinking if there is already a implementation of this out there. Thx in advance! Cyas.- You can find a good tutorial here: Link The collision part is easy. Check if the distance between the spheres centers is less than the sum of their radius. As for the bounce, you need to swap the

Calculate on which side of a line a point is

元气小坏坏 提交于 2019-11-30 19:41:30
问题 I need to figure out how to calculate on which side of a line a point is. I'm searching a really fast and simple collision algorithm because I just need to know on what side a object is to define a collision state. Just like: if(x > line.x) return EnumSide.LEFT; But the line needs to be diagonally. Any ideas? 回答1: Given a directed line from point p0(x0, y0) to p1(x1, y1), you can use the following condition to decide whether a point p2(x2, y2) is on the left of the line, on the right, or on

javascript collision detection between drawable circles

匆匆过客 提交于 2019-11-30 19:19:32
First of all please don't be too critical with my English. I'm not a native speaker. I hope I can explain myself never the less! Further more, I read that I should show I made some efforts to solve the given problem myself. To show this my post became relatively long. What I want to do: I am new (three weeks) to javascript and I try to build a pool billiard table via html5 canvas and javascript. In the end a user should be able to present a certain playing situation on the virtual pool tabe by dragging the sixteen balls around. I found a lot of hints here on stackoverflow concerning paths and

box2d collision groups

旧巷老猫 提交于 2019-11-30 18:28:10
does anyone know whether bodies only collide when (body1.categoryBits & body2.maskBits) && (body1.maskBits & body2.categoryBits) ? or do they already collide when (body1.categoryBits & body2.maskBits) || (body1.maskBits & body2.categoryBits) ? If anyone is still looking for more explanations, I made a detailed tutorial here : http://aurelienribon.wordpress.com/2011/07/01/box2d-tutorial-collision-filtering/ From the Box2D manual : 6.2.3. Filtering Collision filtering is a system for preventing collision between shapes. For example, say you make a character that rides a bicycle. You want the

New velocity after circle collision

混江龙づ霸主 提交于 2019-11-30 17:19:57
问题 On a circular billiard-table, the billiard-ball collides with the boundary of that table with some velocity v1. This collision is detected as follows: double s = sqrt( (p.x-a)*(p.x-a) + (p.y-b)*(p.y-b) ); if (s<r) // point lies inside circle // do nothing else if (s==r) // point lies on circle // calculate new velocity else if (s>r) // point lies outside circle // move point back onto circle (I already have that part) // calculate new velocity Now how can the new velocity v2 after the

Dragging collisions

独自空忆成欢 提交于 2019-11-30 09:58:38
问题 I am pretty new to both CANVAS and Kineticjs but I feel what I am attemping should be much easier then I am making it out to be. Basically this is what I have so far: The code I am attempting to use is from kineticjs Stop drag to a shape when overlaps with another solution but was unable to get it to work. Please check the live jsfiddle code var isRectCollide = function(target, box) { if (target.x - target.width >= box.x + box.width && target.y - target.height >= box.y + box.height && target

Collision between two elements with rotating

不打扰是莪最后的温柔 提交于 2019-11-30 08:52:34
问题 var keys = new Array(); var direction; var direction; var iNr = 0; $(document).ready(function(){ looper(); $("#demo1").css("margin-top", 400 + "px"); $("#demo2").css("margin-left", 380 + "px"); myFunction(); }); function myFunction() { iNr = iNr + 0.5; $("#main").css("transition","all 0.1s"); $("#main").css("transform","rotate(" + iNr + "deg)"); setTimeout(function() { myFunction(); }, 50); } function looper() { var p =$("#circle"); var offset = p.offset(); var t =$(".red"); var roffset = t

Sphere - sphere collision detection -> reaction

落爺英雄遲暮 提交于 2019-11-30 04:42:52
问题 I need to make an algorithm that detects when two spheres collide, and, the direction that wich one will take an instant after the collision. Let say, Imagine like when you open your table in a pool match, all the balls are colliding one to another "randomly". So, before starting to write the code myself, I was thinking if there is already a implementation of this out there. Thx in advance! Cyas.- 回答1: The collision part is easy. Check if the distance between the spheres centers is less than

Dragging collisions

情到浓时终转凉″ 提交于 2019-11-29 17:43:19
I am pretty new to both CANVAS and Kineticjs but I feel what I am attemping should be much easier then I am making it out to be. Basically this is what I have so far: The code I am attempting to use is from kineticjs Stop drag to a shape when overlaps with another solution but was unable to get it to work. Please check the live jsfiddle code var isRectCollide = function(target, box) { if (target.x - target.width >= box.x + box.width && target.y - target.height >= box.y + box.height && target.x + target.width <= box.x + box.width && target.x + target.height <= box.y - box.height ) return false;

Detect if line segment intersects square

本小妞迷上赌 提交于 2019-11-29 14:48:58
Anyone have a simple algorithm for this? No need for rotation or anything. Just finding if a line segment made from two points intersects a square Eric This code should do the trick. It checks where the line intersects the sides, then checks if that is within the width of the square. The number of intesections is returned. float CalcY(float xval, float x0, float y0, float x1, float y1) { if(x1 == x0) return NaN; return y0 + (xval - x0)*(y1 - y0)/(x1 - x0); } float CalcX(float yval, float x0, float y0, float x1, float y1) { if(x1 == x0) return NaN; return x0 + (yval - y0)*(y1 - y0)/(x1 - x0); }