question

Orry avatar image
0 Likes"
Orry asked Jason Lightfoot commented

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

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

FlexSim 23.1.3
kinematics
1687964560268.png (48.0 KiB)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Natalie White avatar image Natalie White commented ·

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 0 ·
Orry avatar image Orry Natalie White commented ·

Ok, thanks for you reply

0 Likes 0 ·

1 Answer

Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Jason Lightfoot commented

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;
· 6
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Orry avatar image Orry commented ·
Thank you, I'll try it later
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Orry commented ·
You can also use more vector operations to define a line and then the shortest distance of an object to it.
0 Likes 0 ·
Orry avatar image Orry Jason Lightfoot ♦♦ commented ·
Sorry, does the vector means x, y, z axis? I don't know much about this
0 Likes 0 ·
Show more comments