Collision Detection algorithm for Selection advice - algorithm

I don't know if this is proper platform for the question.
I'm trying to develop a collision detection algorithm.
In my system the primary host (a vehicle) is either stationary or is in motion (in xy, yz and xz plane).
Incoming projectile can either follow a strait path or non-linear trajectory (guided projectile).
Can anyone advice me on proper Collision Detection algorithm!
Initially I thought in terms of equation of a straight line in two-point and further extrapolating (using linear regression) to check if the projectile is impacting the host. This approach might work for unguided or high speed projectile but however on guided projectile this approach will not work due non-linearity and stochastic nature of real-world.
I wish to know if the projectile follows a ballistic trajectory or curved trajectory how can I detect collision. Is their any recommended algorithm.
I have created a Minimum bounding box (i.e. vehicle boundary - a cube) around my vehicle, I am having difficulty selecting/deciding on algorithm on how to track a projectile (say 400 meters away), if the projectile is converging/impacting on my vehicle boundary.

Related

How to resolve this physical collision with impulses?

I've started to write a physics engine but became stuck on some physics of resolving collisions. Let's say I have this situation:
I.e. body B is going towards body A at the speed of 1 space units/time unit. Both A and B have the same mass of 1 unit. Let's consider a completely elastic collision.
I've read in a book (Game Physics Engine Development) that an impulse-based approach can be used to resolve the collision (i.e. find out the linear and angular velocities of both bodies after the collision). As I understand it, it should work like this:
When the bodies collide, I get the point of the collision and the collision normal.
At the point of the collision I consider only two points colliding in the direction of the normal (the points at which the bodies are touching, i.e. I ignore the shapes of both bodies) and I compute the new velocities of these two colliding points (this is easy to do, there is a simple formula found e.g. on Wikipedia).
I find an impulse such that when applied to both bodies at this point it achieves the computed velocities for these two points.
Now the problem arises when I consider that from a physical point of view both momentum and kinetic energy need to be conserved. With these constraints in mind there is seemingly no solution, because:
When B collides with A, B should come to complete stop and transfer all its momentum and kinetic energy to A, according to elastic collision formula. In order for linear momentum to stay conserved, A then has to start linearly moving left at the same speed as B was before the collision (as they have the same mass). So now A has the same kinetic energy as B had, which however means that A cannot come into rotation because that would add additional kinetic energy to it (as rotating adds kinetic energy as well as linear motion), breaking the conservation of kinetic energy. Nevertheless, the physically correct solution IS for A to both move linearly to the left AND rotate as B colliding at this location exerts torque (and I've also checked real life object behave this way). Note that we cannot take away some energy of A's linear motion and add it to the rotation as that breaks the conservation of linear momentum.
The only "real" solution is that B doesn't come to complete stop and keeps some momentum while A will be both moving left and rotating. But this doesn't seem to be doable with the impulse-based approach that only takes into account the two colliding points, the elastic collision formula simply say the point at B should come to stop and as B cannot receive any torque (the collision happens in its middle), the only way to fulfill this is for B to stop moving.
So is there something I missed? Is the impulse-based approach just not physically correct? I appreciate any insight and suggestions on how to correctly resolve the collision. Thanks!
The formulas that you're looking at are for the collision of two point masses. Point masses can't have angular momentum, and so the formulas have no room for that term.
You have to go back to first principles.
Suppose that an edge collides with another body at a point (think corner hitting an edge). Then a specific impulse is imparted at that point, in a direction normal to the edge. (Any other direction would have required friction, which would make this a non-elastic collision.) The opposite impulse is imparted to the other body, along the same vector. Imparting opposite impulses to both bodies is sufficient to guarantee both conservation of momentum and angular momentum. But conservation of energy is going to take some work.
Next, what happens when we impart that momentum? As this physics answer says, we impart momentum as if the impulse happened to the center of mass. We impart angular momentum equal to the cross product of the impulse and the moment arm (the vector describing how much the impulse misses the center of mass). This will cause the body to start rotating at a rate of the impulse divided by the moment of inertia.
You get kinetic energy from the motion of the center of mass, but also kinetic energy from its rotation.
So in your 2-D collision you now have the following facts:
The mass of each body.
The velocities of each body.
The moment of inertia of each velocity.
The angular velocity of each body.
The moment arm of the line of force for each body.
You can now calculate the kinetic energy of the whole system, as a function of the magnitude of the specific impulse. Unlike the point mass, ALL of these factors play into it, making the equation complicated. However, like the point mass, you'll get a quadratic equation with 2 solutions. One solution is 0 impulse imparted (representing the system before the collision), and the other is your answer afterwards. Complete with changes to the momentum and angular momentum of both systems.

High-velocity collision tests between points and triangles

I'm running a very simple particle simulation where I move particles around in space.
Particles are represented as simple 3D points in space, and their movement is achieved by incrementing their position with a velocity vector (newPos = oldPos + velocity).
I'd like to introduce a form of collision detection where particles can bounce off 3d triangles (simple surfaces defined by three 3D points). A naive approach is to just shoot a ray off each particle in the direction of their velocity vector, with a length of the velocity magnitude of the particle, and if a ray-triangle intersection is detected, go from there to calculate particle reflection vector, etc.
However...if both particles and triangles are moving over time, there are lots of cases where collisions should occur, but that naive approach will fail to detect them. For example, imagine a slow moving particle approaching a fast moving triangle. At a particular simulation step the ray shot out of the particle along its trajectory may not reach a triangle ahead of it...but by the next simulation step the triangle might move so fast that it moves behind the particle and the collision is missed.
Is there a standard way to detect point-triangle collisions that can account for these types of problematic cases? Increasing simulation substeps is of course an option, but not a preferred one since it merely reduces the possibility of a missed collision, rather than preventing them entirely.

3D mesh edge detection / feature line computation algorithm

I have a program that visualizes triangular meshes and allows the users to draw on the meshes using a pen. I want to have a "snapping" mode in my system. The snapping mode performs drawing corrections for the user in the sense that the user-drawn lines are snapped to the nearest edge (or the silhouette) of that part of the mesh.
I'm looking for an algorithm that compute the edges visible on the mesh from a given point of view. By edges, I'm referring to the outlines of the shape: corner points and the lines between them (similar to the definition of an edge in computer vision/image processing -- such as Canny edges).
So far I've thought of two approaches for this:
Edge detection: so far I've only found this paper. Their method is understandable, yet the implementation is not trivial (due to tensor computations and some ambiguity in their explanations). The problem with this approach is that it produces "edge strength values" which is a value in the range [0, 1] for every vertex. The value of 1 indicates an edge vertex with a high confidence. This introduces extra thresholding parameters in the system which I'd rather not have. Their output looks like this (range [0, 1] scaled to [0, 65535]):
Rendering or non-photorealistic methods such as the one asked in this question or this paper. They seem to be able to create the silhouette that I'm after as can be seen below:
I'm not a graphics expert and as of yet I don't know whether their methods can be used for computation of the feature lines rather than rendering.
I was wondering if anybody has any ideas about a good algorithm for what I want to do. Since the system is very interactive, the performance is important. The snapping feature does not have to be enabled all the time (therefore, if the method is computationally expensive, some delay in when "snapping enabled" mode is toggled can be tolerated while the algorithm is computing the edges.) Also, if you know of any implementation (preferably open source), I'd be grateful if you could share it with me.
There are two types of edges that you want to detect:
silhouette edges are viewpoint dependent, they correspond to the places where the line of sight tangents the surfaces. With a triangulated model, they are easy to determine, as they are shared by a front-facing triangle and a back-facing one.
"angular" edges are viewpoint independent and formed by a discontinuity in the tangent plane direction. As a triangulated model has itself this kind of discontinuity, there is no exact criterion to find them. Just set a threshold on the angle formed by two triangles. This threshold must be such that smooth patches do not trigger.
By this approach, you will find the wanted edges in 3D.
This is not enough, as part of them are hidden by other surfaces. You have the option of integrating them as edges in the 3D model and letting the rendering engine do its job, or, if you have the courage, to implement an hidden lines removal algorithm. (The wikipedia link is a little terse.)
Since posting the question, something else came into my head. Since 2D edge detection is a very well-studied problem, one way of tackling the problem is performing 2D edge detection on the projection image of the mesh.
In other words, given a specific view of the mesh, one could generate a 2D image. A 2D edge detection algorithm (such as Canny edge detector) could then be run on the 2D image and the results can be back-projected to 3D to determine the silhouettes of the mesh in question. One possible advantage of this is simplicity!
Edit (2017):
Even though I moved away from this, I returned to this problem again for a different purpose. To anybody else looking into this problem: there is a paper that talks about various contours from meshes that's worth reading (the paper is "Suggestive Contours for Conveying Shape" by DeCarlo et al.).
Working implementation of the methods discussed in the paper are available here.

What "boundary conditions" can make a rectangle "look" like a circle?

I am solving a fourth order non-linear partial differential equation in time and space (t, x) on a square domain with periodic or free boundary conditions with MATHEMATICA.
WITHOUT using conformal mapping, what boundary conditions at the edge or corner could I use to make the square domain "seem" like a circular domain for my non-linear partial differential equation which is cartesian?
The options I would NOT like to use are:
Conformal mapping
changing my equation to polar/cylindrical coordinates?
This is something I am pursuing purely out of interest just in case someone screams bloody murder if misconstrued as a homework problem! :P
That question was asked on the time people found out that the world was spherical. They wanted to make rectangular maps of the surface of the world...
It is not possible.
The reason why is not possible is because the sphere has an intrinsic curvature, while the cube/parallelepiped has not. It can be shown that for two elements with different intrinsic curvatures, their surfaces cannot be mapped while either keeping constant infinitesimal distances, either the distance between two points is given by the euclidean distance.
The easiest way to understand this problem is to pick some rectangular piece of paper and try to make a sphere of it without locally stretch it or compress it (you can fold). You can't. On the other hand, you can make a cylinder surface, because the cylinder has also no intrinsic curvature.
In maps, normally people use one of the two options:
approximate the local surface of the sphere by a tangent plane and make a rectangle out of it. (a local map of some region)
make world maps but implement some curved lines everywhere identifying that the measuring distances must be made according to those lines.
This is also the main reason why when traveling from Europe to North America the airplanes seems to make a curve always trying to pass near canada. If we measured the distance from the rectangular map, we see that they should go on a strait line to minimize the distance. However, because we are mapping two different intrinsic curvatures, the real distance must be measured in a different way (and not via a strait line).
For 2D (in fact for nD) the same reasoning applies.

Surface extraction a fluid .

At a given time-step I have a sampled a lot points from a fluid , and I want to extract the
points which lie at the surface of the fluid. Does any one know a good algorithm
and any available codes to do this?
I am aware of surface reconstruction, but the assumption there is that the sampled points
are on/near the surface. So I guess that would not be too useful here.
Is finding the convex hull of the points adequate? How many points do you have?
Maybe start with a convex hull and then modify it to allow a certian amount of concavity where there are large parts of the surface without any points nearby.
Otherwise try fitting a spline or similar polynomial function to the points. You need some sort of cost metric to measure how good your fit is so that you don't bend your surface too much to reach the inner points. (Unless sharp high curvature sections are allowed for breaking waves etc?)
Is this a tank that get's moved about causing sloshing or something similar - if so there may be some physics model you can used to suggest the shape of surfaces likely to be found. The pattern of motion and speed of waves in the fluid may tell you how many waves etc you'd see.

Resources