MoI discussion forum
MoI discussion forum

Full Version: Parametric design in MoI?

Show messages:  1-4  …  845-864  865-884  885-904  905-912

From: Psygorn (DRILLBIT)
6 Apr 2022   [#905] In reply to [#904]
Hello James,

Thank you for your reply,

Could you help me here:

Why does it seem that the floor function doesn't work properly?



I don't think for the value of A = 117 it should display -1!

How can I get 1 for values of A from 0 to 180, and -1 for values of A from 181 to 360?

Attachments:
Floor_Function_Problem.nod


From: Barry-H
6 Apr 2022   [#906] In reply to [#905]
Hi,
try using the compare node.
Cheers
Barry


Image Attachments:
Screenshot (685).png 


From: James (JFH)
6 Apr 2022   [#907] In reply to [#905]
Psygorn,

quote:
Why does it seem that the floor function doesn't work properly?

It is working properly...given that sin(117) / 2 = -0.34, the floor value will be -1

quote:
How can I get 1 for values of A from 0 to 180, and -1 for values of A from 181 to 360?

Firstly, if working with degrees use square brackets : sin[a] because they convert degrees to radians
used by trigonometric functions.

If you imagine a point revolving around a circle, at any point the sine of the angle: sin[a]
equals the y component / radius, so regardless of the radius the result will be 0 on the horizontal axis
and 1 & -1 at top & bottom of the vertical axis respectively, and the points in-between will give a result
ranging from -1 to 1

There is a lot of better explanation of trigonometric functions online, here is the wikipedia page:
https://en.wikipedia.org/wiki/Sine_and_cosine

James
https://www.instagram.com/nodeology/
From: Psygorn (DRILLBIT)
6 Apr 2022   [#908] In reply to [#907]
>> It IS working properly...given that sin(117) / 2 = -0.34, the floor value will be -1

Hello James, but I think sin(117) = 0.891 even calculator says that!



I assume the value of sin is not calculated in Degree? (I think it is in Rad)

How can I get 1 for values of A from 0 to 180, and -1 for values of A from 181 to 360? in Degrees.
for example I thought if I use : 1+( 2 * floor function of (sin (a)/2)) I could have 1 for 0<a<180 and -1 for 180 <a<360

.>>If you imagine a point revolving around a circle, at any point the sine of the angle: sin[a]
equals the y component / radius, so regardless of the radius the result will be 0 on the horizontal axis
and 1 & -1 at top & bottom of the vertical axis respectively, and the points in-between will give a result
ranging from -1 to 1

Luckily, I know about it! and I know if we imagine a circle and divide it by the largest horizontal segment (it's horizontal diameter) then "sin(an angle in the upper semicircle)" would be positive and "sin(an angle in the lower semicircle)" would be negative. :-)

I just don't know how to do it in Nodeeditor, How to turn all positive values of sin to 1 and negative ones to -1.

Edit: Dear James I always had struggle where t use RAD and where to use Degree!
From: bemfarmer
6 Apr 2022   [#909] In reply to [#908]
The javascript sin(angle) gives the correct result for angle in radians.

For 117 degrees, multiply by (PI/180) yields 2.042... radians. Javascript sin(2.042...) = .891..., which agrees with your calculator set to DEG.

James is correct, in that javascript sin(117) treats 117 as radians, NOT degrees.

Max is using square brackets [ ] for the trig. The math in Max's node is done using Javascript Math functions. Javascript version ES5, NOT ES6.
(I think sin() is the same as sin[] in the node (???))

- Brian
From: bemfarmer
6 Apr 2022   [#910] In reply to [#908]
Google search often yields responses on stackoverflow, which can be helpful, (if understandable)

See last answer here:
https://stackoverflow.com/questions/13975745/the-fastest-way-to-get-current-quadrant-of-an-angle

The degree angle theta needs to be converted to radians, to use the Javascript Math.sin[radianAngle]. (Max removed the need to use Math. in front of sin)

if sin[theta*PI/180] >= 0 , then output is +1.

if sin[theta*PI/180] < 0 , then output is -1.

So compare does seem to be useful. The Sine provides similar benefit to using modulus of +/- angle. Javascript Modulus (%), of angle could be used instead of Sine...

- Brian
From: Psygorn (DRILLBIT)
6 Apr 2022   [#911] In reply to [#909]
Thank you Brian,

Now, I got it!

:)
From: Psygorn (DRILLBIT)
6 Apr 2022   [#912] In reply to [#910]
Thank you again, Brian,

Your explanation helped a lot!

I was able to solve the problem and here are the results:

http://moi3d.com/forum/index.php?webtag=MOI&msg=10641.16

I would be happy to know your opinion about it! (I mean could I do it better?)

Show messages:  1-4  …  845-864  865-884  885-904  905-912