Grasshopper

algorithmic modeling for Rhino

I found myself wanting to write sign(x) in an expression, and there doesn't seem to be an easy way to do it; I'm going to use a conditional instead.

Views: 1642

Replies to This Discussion

Sin(x) you mean?

I think it refers to the SIGN transfer function of Fortran days.

Where you could specify two variables Sign(x,y) which would change the sign of x if y was different.

eg

sign(1,2) = 1

sign(1,-2) = -1

sign(-1,2) = 1

sign(-1,-2) = -1

Very odd it didn't seem to display the text.

Here's a VB  Script of it. Probably a more elegant way to achieve this but it would do for now 

Attachments:

Thanks.

I was thinking more of the more modern sign() function, where:

                   -1 if x < 0

sign(x) =        0 if x = 0

                    1 if x > 0

This can be used as a sign transfer function by multiplication:

  sign(x) * whatever

I ended up writing something like "if(x>0,1,-1)", which worked, but isn't very elegant.

A very late note in this thread; this is called the "signum" function, usually denoted "sgn," though some computer languages make it "sign." See http://mathworld.wolfram.com/Sign.html.  I still wish Grasshopper included it.

Try to use  if(x<0,-1,0)+if(x>0,1,0) , why would be not ....

...or if(x=0,0,x/abs(x)) ......

here is a sign function python component:

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service