LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pythagoras calculation

Solved!
Go to solution
Highlighted
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
(1,256 Views)
Highlighted
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!

This account is no longer active. Contact ShadesOfGray for current posts and information.
Message 2 of 3
(1,232 Views)
Highlighted
Thanks. Being able to perform operations on the entire array fixed my problem.
0 Kudos
Message 3 of 3
(1,226 Views)