How to measure the distance between two objects in real-time

How to measure the distance between two objects in real-time

Plod
Not applicable
70 Views
9 Replies
Message 1 of 10

How to measure the distance between two objects in real-time

Plod
Not applicable

[ FlexSim 23.1.3 ]

Hello

As the title, when I run a kinematic, I want to get distance between two objects in real-time, sometimes maybe the object is a line or cube, so that is the problem.


best wishes

1687964560268.png

0 Likes
Accepted solutions (1)
71 Views
9 Replies
Replies (9)
Message 2 of 10

natalie_white
Not applicable

Hi @Orry,

This post may be helpful. https://answers.flexsim.com/questions/79893/distance-between-two-objects.html

Can you post your model?

0 Likes
Message 3 of 10

jason_lightfootVL7B4
Autodesk
Autodesk
Accepted solution

For two objects : obj1 and obj2


Vec3 centres=Vec3(0.5,0.5,0.5); // set up centre factors for the axes
updatelocations(obj1);  // in case they are moving
updatelocations(obj2);
Vec3 locDiff=obj1.getLocation(centres).project(obj1.up,model())-obj2.getLocation(centres).project(obj2.up,model());   // projecting onto the model in case they are in different containers/coordinate systems
double distance=locDiff.magnitude;
Message 4 of 10

Plod
Not applicable
Thank you, I'll try it later
0 Likes
Message 5 of 10

Plod
Not applicable

Ok, thanks for you reply

0 Likes
Message 6 of 10

jason_lightfootVL7B4
Autodesk
Autodesk
You can also use more vector operations to define a line and then the shortest distance of an object to it.
0 Likes
Message 7 of 10

Plod
Not applicable
Sorry, does the vector means x, y, z axis? I don't know much about this
0 Likes
Message 8 of 10

jason_lightfootVL7B4
Autodesk
Autodesk
Yes - here's the Vec3 documenation.
0 Likes
Message 9 of 10

Plod
Not applicable

Hello

I use your code in my model, but when run, the text will be invisible, how can I fix it?


Thanks

1688025292455.png

0 Likes
Message 10 of 10

jason_lightfootVL7B4
Autodesk
Autodesk

You need this:

textnode.value=string.fromNum(distance,2);
0 Likes