# Measure between 2 3D points

## Recommended Posts

Hi, there is a node that measures between 2 points in 2D but can't seem to find out how to measure between 2 Vectors. (eg, (0, 20,30) & (60, 200,300).

```def get_length_2_3DPts(Pt1, Pt2):
# lngth = sqrt --> sqrd(x2-x1) + sqrd(y2-y1) +sqrd(z2-z1)

def square_cust(n1, n2):
return vs.Sqr(n2 - n1)

lngth = vs.Sqrt(square_cust(Pt2[0], Pt1[0]) +
square_cust(Pt2[1], Pt1[1]) +
square_cust(Pt2[2], Pt1[2]))
return lngth```

Edited by twk
fixed

Hi, Thanks for this. I have tried to format a node with this but I don't seem to be able to get an output distance.

Can you  have a look at the node please.

Thanks

Distance 3D.vwx

Alan,

Try this. I think the code above represents a function you would call to get a result. I took out that formatting and just made it the code of the node instead. It seems to work as expected

(The file also includes a version of the node where the function is called. I suspect in this case it should actually be cleaned up to remove the duplicate variable names etc.. The first version is way cleaner for a node.)

Kevin

Distance 3D KM.vwx

Edited by Kevin McAllister

@Kevin McAllister 's version is correct. Apologies, I forgot I was in the Marionette section.

Thanks, Amazing what removing one line of code can do.

We just need to change the heading to "Get 3D Distance" as it actually calculated the length of the line in 3D.

Edited by Alan Woodwell
Rename Node

@Alan Woodwelldid you see this link to an article about vectors in Vectorscript?

@MarissaFit would be great if there was a way to have some articles like this that relate to Marionette. I'm not sure what this resource actually is as its not the official Developer Wiki...

Kevin

Edited by Kevin McAllister
The link wasn't to the official Developer Wiki but some sort of third party Wiki....

No, but thanks. This sort of stuff really makes the brain work overtime and once you understand the concept things become clearer.

Edited by Alan Woodwell

With regards to the Vectorlab.info website; I myself had wondered what it was as well.

From the guy who created it :@orso b. schmid

Quote

No Tui, we are 'tolerated' by Nemetschek. Never acknowledged, not once. But never forget: initially all was done by Frank Brault, who moved on to other Nemetschek tasks.

Also we are tolerated because there is obviously no intention to compete with the Developer Wiki. I am myself a passionate (read obsessed) editor on dev, which I beg you to consult, when it's about the singular routines.

It really is an invaluable resource, and in my opinion should be acknowledged at least by the Vectorworks Devs;

For example, on this page : http://www.vectorlab.info/index.php?title=Index_pitfalls; It clearly states the problems one might encounter with regards to Index and certain vectorscript/SDK calls(procedures/functions)..

Its interesting to hear the background of it and its sadly true that the Developer Wiki has its challenges. I found my experiments with Vectorscript a few years ago frustrating because of the poor documentation. Ultimately something is going to have to happen for Marionette to reach its full potential with end users.

Kevin

Searching through the VS:Function Reference I came across another way to measure between 2 3D points. Node Attached.
Just another way.
For me its all about the learning, so yes maybe a long winded way to do something but I learnt a bit in the process.

Edited by Alan Woodwell

You guys put a lot more work into this than I have for getting a distance, haha

I usually just use the two points as input for a line (or NURBs curve) and use the length node from the object info category (I apologize if my node name/location are incorrect, I'm doing this by memory...). After I've returned the length, I just delete the line/NURBs. I guess it's the lazy in me!

I guess there is always something to learn.

Edited by Alan Woodwell

Thanks for sharing. I find it interesting to hear about all the different ways to do something. Marissa, your way is super simple!

In the end though, it is good to discover the most efficient way if you're using heavy VW files. Extra code, nodes or objects to delete could become a liability if there were 100 separate instances of your Marionette object in your 200mb file

Kevin

Hi, is there a faster and more efficient way to get the distance 3D than what I have in the attachment. I cant seem to get the network to less than 2 main nodes without using the new node.

Distance 3D.vwx

Edited by Alan Woodwell
.

I'm not actively using marionette but isn't there a magnitude node present in the default nodes folder under "math" ?
I would be surprised if there isn't as this is a really basic math function.

As a general rule, I wouldn't create and delete objects for the sake of calculating something.
You might even run into objects being restated when you undo one step and this isn't a performance friendly solution.

Magnitude |v| = √( x2 + y+ z2 )
The magnitude is calculated with the vector between your two points, being v2-v1.

What about the native "Distance" Node?

Ello, Where did you find this one??
Don't worry  found it. And yes works a treat. The best thing about all these questions is gaining knowledge as to whats available to me  in the program when faced with a problem. More choices. Thanks to all for your comments and contributions.
Hippocode, what you have suggested is what is actually in the Distance node that DomC pointed out and the best  thing is I can see how to put that formulae into a Node (even though I don't understand it, LOL).
For those Noobs like me the second image explains it so now I understand.
Thanks

Edited by Alan Woodwell

## 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.

×