# How do I get the contact point for a 1D ray/slab test?

This topic is 3217 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If I have a 2D ray slab test I can normally get the contact point by using the following equation: contact.point = ray_Origin + tb_Enter * ray_Direction; However when a ray is 1D then I no longer have a second dimension for the point:
private static bool RaySlabIntersect(float slab_Min, float slab_Max, float ray_Origin, float ray_End, float tb_Enter, float tb_Exit,
ref Contact2D contact)
{
float ray_Direction = ray_End - ray_Origin;

// If ray is parallel to the slab
if (Math.Abs(ray_Direction) < float.Epsilon)
{
// Ray is parallel to slab, but NOT inside the slab
if (ray_Origin < slab_Min || ray_Origin > slab_Max)
{
return false;
}
}
else
{
// Compute intersection t value of ray with near and far plane of slab
float ood = 1.0f / ray_Direction;
float ts_Enter = (slab_Min - ray_Origin) * ood;
float ts_Exit = (slab_Max - ray_Origin) * ood;

// Make "ts_Enter" be intersection with near plane, "ts_Exit" with far plane
if (ts_Enter > ts_Exit)
{
Math_Ext.Swap(ref ts_Enter, ref ts_Exit);
}

// Compute the intersection of slab intersection intervals
tb_Enter = Math.Max(tb_Enter, ts_Enter);
tb_Exit = Math.Min(tb_Exit, ts_Exit);

// Exit with no collision as soon as slab intersection becomes empty
if (tb_Enter > tb_Exit)
{
return false;
}
}

// How do I assign contact location?
//contact.point = ray_Origin + tb_Enter * ray_Direction;

return true;
}

How do I obtain the contact location in 2D for the above test? Do I use the current axis being tested in some way? Thanks.

1. 1
2. 2
3. 3
Rutin
14
4. 4
khawk
11
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633671
• Total Posts
3013267
×