Hi,

I’ve now setup my little simulation environment (pretty simple one) and I have a “robot” between walls, now I’d like to add sensor like objects to be able to calculate the distance between the sensor and the wall for example.(such sensor as laserfinder, to measure the distance perpendicular from the object I measure to the wall.)

Anyone knows algorithm or sample code to do that ?

I’ve googleized some but haven’t found anything useful.

Thanks !

G

I’ve found that a bewildering number of seemingly complex problems in 3D can be solved using a very simple technique. Given a known vector, or two, ask yourself how you can combine them to get the information you need. In the case of the laser sight to the wall, the question is how can I combine my known position and the wall’s normal to get the answer.

You can phrase this question with vectors:

dot(P + N * x, N) = D

In words, if I scale the wall’s normal by some amount, x, then add it to my position, I will have a point on the wall’s plane. Now all that is needed is to solve for x.

x = D - dot(P,N)

The point on the plane is then

P’ = P + N * (D - dot(P,N))

The signed distance of the point to the plane is simply the difference of point distances

dist = dot(P,N) - D

where D is any point on the plane dotted into the the plane’s normal.

A whole slew of problems can be solved in exactly the same way. Just think, what can I scale this by and add to that to get the other.

By the way, you might consider the Math and Algos forum next time for this kind of stuff

thanks sg, i’ll dig into that simple way to calculate it