# Distance between 2 Prims (faces only)

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

I need a way that calculates the accurate distance between two selected prim faces using the mouse.

I select those faces the same way I do it when I need to change the texture surface.

##### Share on other sites

Apart from the fact that you haven't defined what the "accurate distance between two selected prim faces" would be to you, I'm almost sure it's not possible the way you describe it - at least not with the standard viewer.

##### Share on other sites

Hi, that could be easy or it could be squishy, the distance between faces can mean lots of things! We have llDetectedTouchPos, we can use that with llVecDist to get simple point distances. llDetectedTouchNormal can add enough information to find planes. llDetctedTouchST can add enough more to find the middle of a face. Combine these to find the distance between face centers, parallel planes, or what you need. It gets more squishy if the faces are not flat, the object is moving, etc.

##### Share on other sites

Hmmm....  That question would only make sense if the two faces were parallel to each other.  Otherwise, you'd be asking for the distance between a point on one face and a point on the other one.

If you want to know the precise distance between faces on a single prim, there's no magic at all. Just look at the prim's dimension in the direction perpendicular to the faces.  That is, if you have a 1m cube and you want to know have far apart the faces are, the answer is ... tada!... one meter.  The distance between the top and bottom faces on a cylinder that is 2m tall is 2m. And so forth.

If you're looking for the distance between faces on different prims, it still only makes sense if the faces are parallel. You could write a rather complicated script to identify the two faces, get their orientations, verify that they were in fact parallel, and get the distance between them. Doable, but not easy. I recently spent a long time trying to write a script to measure the precise distance between two walls in a room and found that it can be done if the walls are not linked, but is virtually impossible if they are.

##### Share on other sites

... and then there's the fun of deciding if you want face centers (and remember, prim face center and region face center may not be the same), nearest points on the plane, nearest point on plane to the center of the other, or some other arbitrary set of points....

it might actually help more if you told use what you were trying to accomplish with the measurement, as there may be another simpler way to get what you want than direct measurement between faces

ETA:
did I realy take > 5mins to write that? or am I seeing a distrubuted update of posts.... because Roligs wasn't there when I hit reply =/

##### Share on other sites

:smileyvery-happy: So Rolig Loon and me are trying to figure out the same?

Anyway, my posting here, the question is actually simple yet confusing because there are different ways.

I want to stick on the distance between two walls.

It is correct that this way only works on a flat standard Prim surface/face.

##### Share on other sites

Isn'T that just eh

Get Position of both prims, substract/add half their size and width to get to correct "outer point", Get Distance?

##### Share on other sites

isn't this answer just eh ( eh?)

I could do the same to find out the distance between 2 avatars ( to save me a script for any radar)

##### Share on other sites

So I tried this:

No idea if it works of if you want that lol.. Bet it can be shortened, but I wanted to keep it easy while trying

integer bufferPrim = -1;integer bufferFace = -1;//Basically the "direciton" of cube faces there... so face 0 is upwards and so onlist faceMod = [ <0,0,1>, <0,-1,0>, <1,0,0>, <0,1,0>, <-1,0,0>, <0,0,-1> ];default{    state_entry()    {        llSay(0, "Hello, Avatar!");    }    touch_end(integer total_number)    {        integer tFace = llDetectedTouchFace( 0 );        if( tFace == -1 ) return;                        if( bufferPrim == -1 )        {            bufferPrim = llDetectedLinkNumber(0);            bufferFace = tFace;            return;        }        else        {            //Get both prims position and sizes            list primInfo = llGetLinkPrimitiveParams( bufferPrim, [ PRIM_SIZE, PRIM_POSITION ] );            vector prim1Size = llList2Vector( primInfo, 0 );            vector prim1Pos = llList2Vector( primInfo, 1 );            primInfo = llGetLinkPrimitiveParams( llDetectedLinkNumber(0), [ PRIM_SIZE, PRIM_POSITION ] );            vector prim2Size = llList2Vector( primInfo, 0 );            vector prim2Pos = llList2Vector( primInfo, 1 );            //Get the direciton modificator for the face            vector faceVec = llList2Vector( faceMod, bufferFace );            llOwnerSay("Applying face modificator 1: " + (string)faceVec);            //Filter out the unneded directions and divide by 2, because we go from center            prim1Size = <prim1Size.x*faceVec.x/2.0, prim1Size.y * faceVec.y / 2.0, prim1Size.z * faceVec.z/2.0>;            llOwnerSay("Mod: "+ (string)prim1Size);            faceVec = llList2Vector( faceMod, tFace );                        llOwnerSay("Applying face modificator 2: " + (string)faceVec);            prim2Size = <prim2Size.x*faceVec.x/2.0, prim2Size.y * faceVec.y / 2.0, prim2Size.z * faceVec.z/2.0>;                        llOwnerSay("Mod: "+ (string)prim2Size);            //Add the filtered size to the position, now the position vectors are on the center of the faces            vector facePos1 = prim1Pos + prim1Size;            vector facePos2 = prim2Pos + prim2Size;            //Get distance            float dist = llVecDist(facePos1,facePos2);            llOwnerSay("Dist:"+(string)dist);            bufferPrim = -1;            bufferFace = -1;        }    }}

Tried with:

The distance returned when clicking both "inner" faces was about the same as the Red Prim i pulled up between the 2 was

##### Share on other sites

Hehehe..  It feels like just ... eh. I know that it shouldn't be hard, in theory. If you know that the two prims are parallel, so you don't need to test for that, and if they are not linked, then it IS simple (almost).  You just create a scripted object that looks at one of the prims with a nice, narrow scan and senses its position with llGetPos.  Then turn it around, look at the other prim and do the same thing.  The disatnce between their centers is the sum of the two measurements. Then all you have to do is subtract half the thickness of each prim to get the distance between their faces .... if you knew how thick each prim was.  There's no way to get that last bit with a sensor, though, so ..... um... not so easy after all.

If the two prims are linked, the method I just outlined won't work at all, because the sensor will return the position of the linked object, not the centers of the individual prims. On to Plan B. Shoot a butlet at one prim and have the bullet report its position when it hits.  Then shoot another bullet at the other prim and do the same thing.  Use llVecDist to get the distance between the two positions. Easy, and no need to know the prims' thicknesses, right? Well, no, not quite.  When you try that, you find that the reported positions depend on (a) how fast the bullet is going, (b) how big the bullet is, and © some random factor that I could never figure out, despite wasting the better part of a long weekend.  In short, the measured distance is not consistent, not accurate, and WORTHLESS.

Sorry for the long response, but I really did waste a long weekend last month trying to answer this same question and I felt like sharing the frustration.  :smileytongue:  It's a whole lot easier to rez a prim, stretch it to fit between the two faces, and measure its length.

##### Share on other sites

Ah, yes.  But that requires you to put a script into the prims that you are trying to measure.

##### Share on other sites

Link the prims and use llGetLinkPrimitiveParams() to find both their position and size.

##### Share on other sites

Again, though, that works if you are putting a script into the things you are trying to measure, but not if you are designing a remote system.....something like a carpenter's laser ruler. If you want to stand in a room with some scripted device and point it at a couple of walls to find the distance between them, llGetLinkPrimitiveParams won't work.  Also, in the general case you can't count on the prims being linked, and linking the prims may not always be an option, so you need a method that will work on unlinked prims too.

##### Share on other sites

Well he never said it has to be remote, did he?

Well I'll try a remote system

##### Share on other sites

That's is totally correct Rolig.

If there is no other way than a script inside the Prims that's fine too (just annoying). Yes, I didn't say it must be  a remote system.

I am not sure if this is doable without viewer modification but the method inside Phoenix viewer can apply align points to any Prim surface/edge.

##### Share on other sites

Yup that is correct

I did not say it must be a remote system. Rolig is already a step further with her work and thoughts.

I am thankful for any way that makes it work - with scripted Prims or without.

##### Share on other sites

Ah, well, then.  That was my faulty assumption.  If you are content with a system that involves dropping a script into the prims, the solution is quite simple. Use Ixia's solution, which is nicely done.  If any of the prims you use it on already contain scripts that might interfere with it, be sure to set those scripts to not running while you make your measurement. Otherwise, their touch_start events may mess you up.

I am still intrigued by the challenge of making a remote system, and frustrated that I haven't been able to create a system that gives reproducible, precise results.  It would be a lovely tool.

##### Share on other sites

Yes It would be the most lovely building tool ( it is still the most missing tool for builders - actually )

Please do not think you are wasting any time of your weekends trying to make this work

PS: We could put that into the JIRA thingy ?  lol