Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → A line intersects a plane where?
A line intersects a plane where?
2006-01-20, 5:31 PM #1
That is correct, I have figured out a way in which to find the exact point in which a point lines within a plane.

Code:
vector1 = VectorSub(GetSurfaceCenter(testsurf), GetThingPos(testthing)); // Not normalized 
vector2 = VectorScale(GetSurfaceNormal(testsurf), -1); // Normalized 
vector3 = GetThingLVec(testthing); // Normalized 
dist1 = VectorLen(vector1); 
cosine1 = VectorDot(VectorNorm(vector1), vector2); 
dist2 = dist1 * cosine1; 
cosine2 = VectorDot(vector2, vector3); 
dist3 = dist2 / cosine2; 
intersectpos = VectorAdd(GetThingPos(testthing), VectorScale(vector3, dist3));


Hopefully all of my syntax is right, but this is based upon the surface normal being perpendicular to teh plane, created 2 right triangles with one like side, then using that trigonometric ratios to find the length of the vector to add to the position of the thing, the intersects offset if you will. In addition, this can be optimized by checking to see if VectorDot(GetSurfaceNormal(testsurf), GetThingLVec(testthing)) >= 0 (ie, its either perpendicular to it, or it collides with the back of a thing), if it could possibly collide with that surface. Next you can check the dist3 to an outside variable to see if its the first intersecting surface (ie, its the shortest dist3), if checking all surfaces.

Next, this can be coupled with the point on polygon code by Sige, but I dunno how exactly that code works or if it will always work..... but I can improve upon his sphere thing collision.
Code:
vector1 = VectorSub(GetThingPos(point), GetThingPos(testthing)); // Not normalized 
vector2 = GetThingLVec(testthing); // Normalized 
dist1 = VectorLen(vector1); 
sine = VectorLen(VectorCross(VectorNorm(vector1), vector2)); 
dist2 = dist1*sine; 
If(dist2 < radius) intersect = 1;


This is based upon the fact that the closest an object travels to a given point is when the vector between the point and the object is perpendicular to its direction of motion. This forms a right triangle in which the trigonometric ratios can be used as in the previous setup.

Any questions or comments or amazing insights into finding a simple JK point on polygon that I can figure out or knowledge on how Sige's PoP code works, all the helpful. If anyone needs my 3d drawings/triangles/visuals to help comprehend how this works, just ask. Hopefully I got my syntax and logic right as well...... lol And yes this is untested because its based upon mathematical concepts (which really can't be tested), and I don't have the PoP code to run a true test.

BTW - this topic is also available on JKHub, enjoy.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2006-01-22, 3:48 AM #2
I bet this is pretty useful, and remember trying to achieve it but failing miserably, but I'm too lazy to figure it out at the moment. Too complicated, man (some remarks wouldn't hurt, don't you think...it helps you understand your code even some years later...).
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2006-01-22, 5:11 AM #3
So much vector math... :eek:

*splodes*
And when the moment is right, I'm gonna fly a kite.
2006-01-22, 9:17 AM #4
hopefully helpful diagram to explain my point, however, this requires that you know the properties of cosine, triangles, and 3d/2d convertions and rotations.

http://www.jkhub.net/project/screens/project-207-gm4Fec0ji8.jpg
[I linkified your img tag... -gbk]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack

↑ Up to the top!