collision-detection

Collision detection of huge number of circles

一世执手 提交于 2019-11-27 06:29:27
What is the best way to check collision of huge number of circles? It's very easy to detect collision between two circles, but if we check every combination then it is O(n 2 ) which definitely not an optimal solution. We can assume that circle object has following properties: Coordinates Radius Velocity Direction Velocity is constant, but direction can change. I've come up with two solutions, but maybe there are some better solutions. Solution 1 Divide whole space into overlapping squares and check for collision only with circles that are in the same square. Squares need to overlap so there

What happens when hash collision happens in Dictionary key?

半城伤御伤魂 提交于 2019-11-27 05:33:15
问题 I've been coding in c++ and java entirety of my life but on C#, I feel like it's a totally different animal. In case of hash collision in Dictionary container in c#, what does it do? or does it even detect the collision? In case of collisions in similar containers in SDL, some would make a key value section link data to key value section like linked list, or some would attempt to find different hash method. [Update 10:56 A.M. 6/4/2010] I am trying to make a counter per user. And set user # is

Detecting collision of rectangle with circle

依然范特西╮ 提交于 2019-11-27 04:18:56
问题 Actually I am trying to detect thee collision of the Rectangle with the circle in the following piece of code:- function checkCollision() { //checking of the Collision if (ry + rh > cy - radius && rx + rw > cx - radius && rx + rw < cx + radius ) { dy = -dy; } } This is also the part of my code:- var rx = 50; //distance from the x-axis of the Rect. var ry = 50; //distance from the y-axis of the Rect. var rw = 80; //width of the Rect var rh = 30; //Height of the Rect. // Distance to moved of

Bounding ellipse

血红的双手。 提交于 2019-11-27 04:05:31
I have been given an assignement for a graphics module, one part of which is to calculate the minimum bounding ellipse of a set of arbitrary shapes. The ellipse doesn't have to be axis aligned. This is working in java (euch) using the AWT shapes, so I can use all the tools shape provides for checking containment/intersection of objects. Jacob You're looking for the Minimum Volume Enclosing Ellipsoid , or in your 2D case, the minimum area. This optimization problem is convex and can be solved efficiently. Check out the MATLAB code in the link I've included - the implementation is trivial and

Can someone explain per-pixel collision detection?

半城伤御伤魂 提交于 2019-11-27 03:27:29
问题 Can someone explain the pros and cons of it and any math involved with it? 回答1: For 2D: You do not need any math for this problem, you need only a custom bitblit-routine. You will blit collision candidates into a hidden surface by painting their collisionmasks onto this surface and checking, if the pixels you just want to draw are (pixel != 0) . Then you will have a collision. Of course, you should precheck by bounding rectangles if an collision can occur. For 3D: You will need math(a lot)!

Unity Physics2D.Raycast hits itself

大城市里の小女人 提交于 2019-11-27 02:16:28
I'm trying to use Physics2D.Raycast in order to check if the player is on the ground (I know that there are other approaches to check if the player is on the ground but I think that the raycast is the most reliable). The problem is that in my scenario it returns the player itself as hit and I really don't understand why and what should I do. My code (in PlayerController ) is the following: public bool IsGrounded () { Bounds bounds = this.playerCollider.bounds; Vector3 rayOrigin = bounds.center; rayOrigin.y -= bounds.extents.y; RaycastHit2D hit = Physics2D.Raycast (rayOrigin, Vector2.down, 0.1f

Java rectangle collision detection confusion

自作多情 提交于 2019-11-27 02:02:44
I have made a simple 2D state change game using Bucky's slick Java tutorials, I modified this game and now want to set collisions on the map so that my player can not go through the house on the map. I think I kind of have a idea of how collisions work: you make 2 rectangles using the following code: public Rectangle getBounds() { return new Rectangle(x, y, width, height); } 1 for the player and 1 for the obstacle, how would I put this into my code and how would I tell java that the rectangle for the obstacle is different to the player rectangle? Then after making the 2 rectangles I would set

Pixel-Perfect Collision Detection Android

孤人 提交于 2019-11-27 01:38:01
Ok so I am working on a game on Android. I need to implement pixel perfect collision detection. I already have the bounding boxes set up around each of the images, each bounding box is transformed to match the current rotation of the image. That all works great. I also have the pixel data from each bitmap stored in an array. Can someone help me figure out the most efficient way to go about detecting if the pixels overlap? Thanks in advance for any help! The basic idea is to create a bitmask for each object where you indicate in each pixel if the object is actually there or not. Then you

Wanted to make an object bounce inside a circle, ended up making the object move along the rim of the circle

拟墨画扇 提交于 2019-11-26 23:47:50
问题 Here's the code in question: public void calculate() { // Center of circle is at (250, 250). //THIS ALGORITHM IS NOW PROVEN TO BE WORSE THAN I FEARED... /* What it does: * Moves object around in a circle. * Does not move the object towards the center. * Object always stays on the rim of the circle. * * Algorithm I used. (DOES NOT WORK): * N is normalized vector. * R = -2*(V dot N)*N + V */ vx += Accelero.X * 0.1; vy += Accelero.Y * 0.1; double nx = x - 250; double ny = y - 250; double nd =

OpenGL GL_SELECT or manual collision detection?

纵然是瞬间 提交于 2019-11-26 22:42:00
问题 As seen in the image I draw set of contours (polygons) as GL_LINE_STRIP. Now I want to select curve(polygon) under the mouse to delete,move..etc in 3D . I am wondering which method to use: 1.use OpenGL picking and selection. ( glRenderMode(GL_SELECT) ) 2.use manual collision detection , by using a pick-ray and check whether the ray is inside each polygon. 回答1: I strongly recommend against GL_SELECT . This method is very old and absent in new GL versions, and you're likely to get problems with