From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pythagoras calculation

Solved!
Go to solution
I have a .vi I am trying to write in Labview for a project that really has me stuck. Basically what I want to be able
to do is calculate distance using pythagoras, given a user selected number of dimensions (up to 20). That means rather
than traditionally just calculating pythagoras using x and y, I now have x, y, z, .... etc.

Currently I am at the stage where I can send an array of integers, where each represents which dimension to use
in calculation. eg 1 is x, 2 is y, 3 is z ... etc.

What I have done is a .vi for just x and y, which I have attatched but as for expanding this for z, alpha, beta,
gamma, delta etc I draw a blank. Any clues?
0 Kudos
Message 1 of 3
(3,123 Views)
Solution
Accepted by topic author eword

LabVIEW will do primitive operations on arrays.  For example, if you connect two one-dimensional arrays into the add primitive, it will return an array that contains and element by element addition of the inputs.  This makes your problem fairly easy.  Instead of indexing individual points, index the entire location vectors of the two points you want to know the distance between.  Subtract one from the other to get the differences.  Square the resultant vector.  Use the Array Sum to sum it, then take the square root.  This approach will scale with however many dimensions you want.

 

Good luck!

Message 2 of 3
(3,099 Views)
Thanks. Being able to perform operations on the entire array fixed my problem.
0 Kudos
Message 3 of 3
(3,093 Views)