Collision Detection of a Projectile on an Object
Mostrar comentarios más antiguos
Hello,
I am doing a simulation in MatLab for my PhD thesis work and it involves shooting projectiles (modeled as point particles with random trajectories) at an object. At first I started with a rectangular plate in 3D space at a distance "z" from the emitter, as this was easy (just define x and y bounds) to see if the projectiles trajectory has hit it but now I want to move on to any irregular object in 3D space.
So what I have done is used an external modeling software to make a 3D object and export it as an .obj. This gives me
1.) Verticie information of the model. 2.) Normal vector information on the model.
What I did in the rectangular plate case was the following.
1.) Randomly assign a projectile a velocity vector [vx,vy,vz]. 2.) Using the standard kinematics equation (z=Vz*t),Plug in the value of "z" that the plate is located at to determine the time it took the projectile to get there 3.) Plug this time value into the x and y components (x=Vx*t and y=Vy*t) to see if x and y are within the bounds of the plate. 4.) If yes, then calculate the reflected trajectory using the following equation. Vr=2*(normal vector dot trajectory unit vector)*normal vector-trajectory unit vector.
The problem I am having with an arbitrary 3D object is, most of the time, the trajectory is going to go BETWEEN the vertices of the model.And I cannot think of a way to fix this issue. I cannot just define bounds as in the rectangular plate case, and I need to be able to determine the normal vector of the point it DOES hit to calculate the reflected trajectory.
Basically the question is, What would be a good way to determine if the trajectory has passed BETWEEN the verticies?
Respuesta aceptada
Más respuestas (1)
Matthew Brandsema
el 24 de Oct. de 2014
0 votos
4 comentarios
Mohammad Abouali
el 25 de Oct. de 2014
In "[V,C]=voronoin(X)" X is your points. V stores the vertices of Voronoi coordinate and C pretty much is the connectivity matrix.
If you want to get the voronoi polygon surrounding point defined by X(i,:) you can construct the polygon as follow:
polygonSurroundingXi= V(C{i},:)
It's good to check that it did not returned any coordinate as inf. if you want to make sure that the last point in the polygon is the same as first point then do this:
polygonSurroundingXi= V([C{i} C{i}(1)],:)
Let's give an example: {This is from MALTAB Help with some modification}
x = [ 0.5 0
0 0.5
-0.5 -0.5
-0.2 -0.1
-0.1 0.1
0.1 -0.1
0.1 0.1 ]
[V,C] = voronoin(x)
so now to find the voronoi polygon surrounding point x(7,:) we can do:
i=7;
plot(x(i,1),x(i,2),'r.','MarkerSize',35)
hold on
plot(V([C{i} C{i}(1)],1),V([C{i} C{i}(1)],2),'b-')
Mohammad Abouali
el 25 de Oct. de 2014
By the way, there is the issue of transparency.
Here is the thing.
1) you calculate where your ray hits the facet. 2) you check with inpolygon that the location is actually within the facet.
Now it is possible that you find multiple facet with valid collision points. If your surface is transparent then that doesn't matter, but if your surface is opaque you must check which facet was hit first, i.e. check the one with smallest t.
Note that it is important to check smaller t after you have made sure that the collision point is within the facet extend. So do that after checking with inpolygon.
Matthew Brandsema
el 28 de Oct. de 2014
Mohammad Abouali
el 29 de Oct. de 2014
One quick solution that comes to my mind is to introduce some fake points around all your points. So this way your real points are not on the edge; hence, they won't have inf as coords in their voronoi facets. And just keep track of those fake points and make sure that you do not include them in your further calculation.
But let me check if Matlab has another option to do this.
Categorías
Más información sobre Voronoi Diagram en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
