Jump to content
AlanW

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

Thanks in advance

Share this post


Link to post

http://www.intmath.com/vectors/7-vectors-in-3d-space.php

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

Share this post


Link to post

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

Share this post


Link to post

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
Re-uploaded file to fix broken link issue

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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.

https://forum.vectorworks.net/index.php?/topic/42750-does-anybody-know-whats-on-with-vectorlabinfo/&do=findComment&comment=216461

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

  • Like 2

Share this post


Link to post

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

 

  • Like 1

Share this post


Link to post

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.

 

Distance 3D_V001.vwx

Get 3D Distance.JPG

Edited by Alan Woodwell

Share this post


Link to post

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!

  • Like 1

Share this post


Link to post

I guess there is always something to learn.

Edited by Alan Woodwell

Share this post


Link to post

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 :D

Kevin

Share this post


Link to post

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

distance 3D.JPG

Edited by Alan Woodwell
.

Share this post


Link to post

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.

  • Like 1

Share this post


Link to post

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

 

Capture.JPG

Capture.JPG

Edited by Alan Woodwell
Add image

Share this post


Link to post

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...