08-20-2018 05:42 AM
Formula Node for subtracting vectors. Works fine for:
Running Vector 1.4 @ 75 degrees, Slow Roll 0.35 @ 65 degrees
Will not give correct answer for:
Running Vector 1.1 @ 265 degrees, Slow Roll 0.35 @ 65 degrees
I know the Formula Node expects radians, but is there also an issue with angles greater than 180 degrees?
Answer for second example should be 1.43 @ 258.
Thanks in advance.
08-20-2018 07:43 AM
Not sure why it doesnt work. I have no experience of the formula node.
For vector subtraction I would use the inbuilt complex datatype like this.
Not sure if this helps or not.
0xDEAD
08-20-2018 07:44 AM
Sometimes it helps to just stop and think about the problem. Your "vector" is a polar representation of a 2D Vector, which can also be expressed as a complex number. In either the 2D Vector formulation (an array of X and Y components) or the complex number formulation, "Vector subtraction" is simply subtracting the two representations.
Your first step is to convert your representation to a true Vector representation. The simplest method may be to use complex numbers, as there is a function, Polar to Complex, that does this (theta, of course, needs to be in radians). Once you have two complex numbers, subtract them, use Complex to Polar, and convert theta back to degrees (if you wish).
The Complex functions are found as a sub-Palette on the Numeric Palette. No Snippet, as the code is so simple, and you will "learn by doing".
Bob Schor
08-20-2018 09:00 AM
You answered my question with your example. Yes, if the angle is greater than 180 degrees, the answer is negative and requires the addition of 2 pi radians! I just adopted your example. Much easier code!
08-20-2018 09:25 AM
The polar space spans -pi to pi radians (rather than 0 to 2pi).
The polar to complex block in labview is nice. It doesnt care that 265 degrees is 4.62512 radians. It converts it behind the scenes to -1.65806 radians for you.
On the output side, there is no conversion it can help with, if the angle is greater than 180 then you will receive a negative angle in radians (since the angle must live in the -pi to pi range). If you want it between 0 and 360 degrees (rather than -180 to 180) you must do that extra conversion step yourself.
0xDEAD
08-20-2018 03:40 PM
@Coryman wrote:
Formula Node for subtracting vectors. Works fine for:
Running Vector 1.4 @ 75 degrees, Slow Roll 0.35 @ 65 degrees
Will not give correct answer for:
Running Vector 1.1 @ 265 degrees, Slow Roll 0.35 @ 65 degrees
I know the Formula Node expects radians, but is there also an issue with angles greater than 180 degrees?
Answer for second example should be 1.43 @ 258.
Thanks in advance.
Just to answer your original question, the reason your formula node did not give the correct result is that you need to use the atan2(x,y) expression instead.
I would still recommend using the complex numbers solution as provided above.
08-21-2018 08:18 AM
If you use built in support for physical quantities, you don't need to convert units. Also, you can use the Quotient & Remainder function to keep the angle positive
08-21-2018 08:50 AM
I keep saying I learn new things in the Forums -- I know I've heard about "Units", but never have used them, and never looked into them. What a useful example, Paul -- thanks.
Bob Schor
08-21-2018 09:17 AM
@paul_cardinale wrote:
If you use built in support for physical quantities, you don't need to convert units. Also, you can use the Quotient & Remainder function to keep the angle positive
I am wary of using LabVIEW units because I was always finding bugs with it in the past.
For example, the square primitive wouldn't square the units (you had to multiply the value by itself as the workaround).
I see that's now fixed in the newer versions, but there were so many issues I had to start manually keeping track of units.
I just made a control with units Deg, used the "convert units" primitive to convert to Rad.
The value is correctly modified but the unit type doesn't propagate to the indicator.
Its a nice trick for the conversion though. Kudos.
0xDEAD
08-21-2018 09:30 AM
Hi deceased,
I just made a control with units Deg, used the "convert units" primitive to convert to Rad.
The value is correctly modified but the unit type doesn't propagate to the indicator.
The "convert unit" does not work this way…
Instead it will convert the value and remove/add the unit. Examples:
When your input is "180 deg" and you convert to "rad" the result will be a value of pi (no unit).
When your input is "180" and you convert to "deg" then the result is "180 deg".