# Finding the distance between objects

## Recommended Posts

yo! so I'm exploring another side of VW scripting that ive hurts my brain... lol

i've built a cable tool that makes Soca Breakouts. part of that plugin involves me putting in how far away the fixture is from my soca breakout and it inserts another cable tool plugin that draws a line between the two and displays some important information. thats working great but i want to automate that even more...

i want to implement a feature that will find the distance between the fixture and breakout for me. i just don't understand the math or what functions i should be using to determine the distance. the truss and fixtures aren't always going to be the same orientation.

below is an example of what I'm calling typical setups... i'm assuming that the truss, fixtures, and soca breakout are all in 1 line. (ill add curved truss support some day) so i don't really need to find the x,y,z distance between them i just need the left or right distance relative to the overall rotation and location of everything.

i've tried using functions like GetSymLoc3D() but it seems to get messy quickly. i've also tried using vs.Perp() and got some good results but only flat angles. i also don't quite understand Math Vectors or how to properly use them.

thanks for the help!

Hey @Jayme McColgan.

Would you mind sketching on the screenshot the actual measurements you're trying to calculate.

Oh, and also where are the insertion points for each plugin object shown there..

Cheers

HTHs

the bottom truss is what the plugin actually looks likes. the other 2 trusses with red lines are in case its hard to see the bottom truss.

the red lines are what I'm trying to calculate and automate.

Thanks, ok, so first things first, I am not familiar with the Spotlight tools,lol. (VW Architect version user). But I assume the plugins work the same.

I'm still not following the diagram above. Am trying to figure out what objects are what.

- Is the gray truss a vectorworks object? I assume the magenta ones are the spotlight fixtures, and your custom plugin is the one labelled Soca breakout?

- And the grey lines are also another custom plugin? The cables one?

Each plugin will have an insertion point and a rotation value attached to it. I would start there and use basic trignometry (soh, cah, toa) to get exact locations and orientations of each object. Then using the vs.Distance call on the values you've calculated.

Could you share a dummy vwx file. I also have a Designer version that can open spotlight stuff.

Cheers,

Tui

sorry let me simply it. my issue doesn't really have to do with spotlight. the image attached is a representation of what i need to achieve. I'm trying to find distance from the blue object to the white object, then i will insert a plugin object that draws a line and other stuff that distance (represented by the red line).

i drew the red line straight because i don't care about the vertical offset i only care about how far away (left or right) the objects is RELATIVE to the overall angle and location in the drawing. i hope that makes sense.

this is hard for me to explain.

@twk i seem to be getting some promising results with just using vs.Distance() i will check back with a progress update in a few days. I'm getting on a plane tomorrow to go to a show.

• 1 month later...

now that i have time to work on this plugin again... ive found a solution for finding the distance between 2 objects using the Pythagorean Theorem... seems to be giving me good results... now i just need to figure out hte logic for if an object is to the left or right of the my source object...

```light_loc = vs.GetSymLoc(handle) ### Get 3D location of Lighting Fixture
dis_a = sym_location[0] - light_loc[0] ### X Distance between Light and PIO Object
dis_b = sym_location[1] - light_loc[1] ### Y Distance between Light and PIO Object

distance = math.sqrt(dis_a ** 2 + dis_b ** 2) ### math... ```

Hello,

i think this is doable, but i have trouble figuring out what exactly you want to achieve or what you mean by "right" or "left" of your source object.

If you mean "with the direction of the truss" and "in the opposit direction of the truss", it can be done like this:

- calculate the (normalized) vector of the truss

- calculate the vector from the breakout to the symbol, has to be parallel to the vector of the truss

- (vector_from_breakout_to_symbol[0] / vector_of_the_truss[0]) gives you a number ((vector_from_breakout_to_symbol[1] / vector_of_the_truss[1]) gives the same number)

- all symbols with a number greater than 0 are on one side of the breakout

- all symbols with a number smaller than 0 are on the other side of the breakout

- if this number is 0 your symbol is on the breakout

Regards,

Letti

On 9/20/2022 at 2:51 PM, Letti R said:

Hello,

i think this is doable, but i have trouble figuring out what exactly you want to achieve or what you mean by "right" or "left" of your source object.

If you mean "with the direction of the truss" and "in the opposit direction of the truss", it can be done like this:

- calculate the (normalized) vector of the truss

- calculate the vector from the breakout to the symbol, has to be parallel to the vector of the truss

- (vector_from_breakout_to_symbol[0] / vector_of_the_truss[0]) gives you a number ((vector_from_breakout_to_symbol[1] / vector_of_the_truss[1]) gives the same number)

- all symbols with a number greater than 0 are on one side of the breakout

- all symbols with a number smaller than 0 are on the other side of the breakout

- if this number is 0 your symbol is on the breakout

Regards,

Letti

vectors have been a voodoo that i haven't quite figured out yet but im trying...

also, yes your graphic is correct. so i guess its back to banging my head against the wall trying to understand how to use vectors. lol

Hello,

a good thing about vector calculation is that its taught in school so there are plenty of good axplanations that can be found online, for example these videos:

Vector between two points and length of a vector:

How to normalize a vector:

And here are the functions i wrote to do this (they may not be well written and only work in 2D):

```def vector_between_two_points_2d(p1, p2):
return((p2[0] - p1[0], p2[1] - p1[1]))

def length_of_vector_2d(v):
return(math.sqrt(v[0] ** 2 + v[1] ** 2))

def normalize_vector_2d(v):
len = math.sqrt(v[0] ** 2 + v[1] ** 2)
return((v[0]/len, v[1]/len))```

Now you only have to do this step to determine on which side the symbols are:

(vector_from_breakout_to_symbol[0] / vector_of_the_truss[0]) gives you a number ((vector_from_breakout_to_symbol[1] / vector_of_the_truss[1])

If you want you can also share a dummy vwx file with the objects, so i can provide better help.

Regards,

Letti

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• KBASE
• #### MARIONETTE

×
• Create New...