LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
James_McN

Degrees to Radians Function

Status: Completed
Available in NI LabVIEW 2010
I think everyone under the sun must have written there own degrees to radians function or vice versa.  Its not hard to do but perhaps it should be available natively as part of the maths palette.
James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
10 Comments
Jim_Kring
Trusted Enthusiast

Here's a simple way to do it.

 

Degrees to Radians Conversion.png

James_McN
Active Participant
Thanks for that, I had just been doing the maths, wasn't aware of those functions.
James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
David_L
Active Participant

Too bad you can't kudos comments.  I learned something new today as well...

Darren
Proven Zealot

Nice one, Jim.  I think I'll post that as a weekly nugget soon.

 

-D

JackDunaway
Trusted Enthusiast

I just performed a benchmark between Jim's convert units method and simply multiplying by the correct factor. I was surprised, initially fearing the proposed method might be orders of magnitude slower than a Multiply primitive.

 

Performing the conversion on an array 10M doubles took about 42msec for both methods (debugging off, controls to avoid constant folding, yada, etc...) when using (as altenbach describes it) the Vestigial For Loop (or was it Appendix For Loop?).

 

When building the array first, then using the polymorphic array instance of both methods, the multiply takes about 74msec, and the Convert Units takes about 106msec. (No additional buffer allocations showed up, don't know why this is slower...)

 

SO... in a nutshell, it looks like the compiler does a good job interpreting a "scary-looking performance killer" into some pretty efficient primitives. 

Darin.K
Trusted Enthusiast

My first thought was that this idea was a bit narrow, I tend to favor an expression node for these conversions anyway.

 

Then, at first glance Jim's idea made me cringe.  I find units to be very annoying and use them less frequently than locals or the stop primitive.  In this case you add and remove the units so the end result is a pure number.  

 

What I would find easier to stomach is a single function which combines the two convert unit functions.  You could specify X and Y to convert X to Y (deg to rad, slugs to kg, scores to fortnights, whatever).  No need to add and remove the units, just do the math.

James@Home
Member

Darin.K

 

It sounds like you'd like to see this program as a VI.

It would be a good project for someone with time to complete.

 

convert.png

 

LabVIEW 5.0 seems so long ago...
CMal
Active Participant

For anyone who is interested, there are two new VIs that ship with LabVIEW 2010:

Degrees to Radians.vi

Radians to Degrees.vi

They can be found in the "<LabVIEW>\vi.lib\Utility\AngleManip\" folder.  Both VIs are polymorphic with support for scalars and 1D arrays of SGL, DBL, and EXT datatypes.

Todd S.
NI Employee (retired)
Status changed to: Completed
 
Todd S.
LabVIEW Community Manager
National Instruments
G-Money
NI Employee (retired)
Status changed to: Completed
Available in NI LabVIEW 2010