Grasshopper

algorithmic modeling for Rhino

Hi guys,

I've been meaning to ask this before, but this post by Danny reminded me:

may I ask: how we can expose these modifiers?
I'm trying to expose the degrees modifier for my Angle (Double) input. I'm working in VS2010, using VB, but I'm quite sure the C# people will want to know this too.

B.t.w. I noticed that the Degrees modifier isn't available yet for any angle outputs at the moment (for instance the Angle and the ArcSin, ArcCos and ArcTan components).

Hope someone can enlighten me on this:)
Kind regards, Pieter

Views: 928

Replies to This Discussion

Parameters just have these build in. You don't expose them, they are always exposed if they are available. If you want the Angle option, use AddAngleParameter instead of AddNumberParameter.

This however is not the end of it. In the BeforeSolveInstance method you should get the UseDegrees property of all inputs that matter and then convert all your angles inside SolveInstance if need be.

So, to recap:

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
   ...
   pManager.AddAngleParameter("Angle", "A", "Angle", GH_ParamAccess.item, 0.5 * Math.PI);

   ...

}

private bool _useDegrees;
protected override void BeforeSolveInstance()
{
   _useDegrees = (Params.Input[X] as Param_Number).UseDegrees;
}

protected override void SolveInstance(IGH_DataAccess DA)
{
  double angle = double.NaN;

  if (!DA.GetData(X, ref angle)) { return; }

  if (_useDegrees)
    angle = RhinoMath.ToRadians(angle);

  ....

--

David Rutten

david@mcneel.com

Thanks for your super fast reply David:) I'm going to see if I can get it to work now; I just started learning some VB. There's no AddAngleParameter in the VS IntelliSense for me, and the codeconverter failed at line 1... I need some time to figure this out. Thanks for pointing me in the right direction, I really appreciate it:)

Which version of GH are you building against?

At an rate, AddAngleParameter just uses AddNumberParameter and it sets the AngleParameter option to True. You can do that yourself as well:

pManager.AddNumberParameter("Angle", "A", "Angle", GH_ParamAccess.item, 0.5 * Math.PI)

DirectCast(pManager[X], Param_Number).AngleParameter = True

--

David Rutten

david@mcneel.com

Version 972.

Well, I just found out that the AddAngleParameter is there for the inputs, I was looking for it to use as an output parameter... Doh! My bad. As I said - just learning:)
And now I understand why none of the Angle (well, Number or Double) outputs have this Degree option:)
Thanks for making me realise where my thinking was off. This helps a lot.

Surely I got the Input modifier for the angle input to work:)
Just posting this for anyone who searches the forum for this too.

I edited the "Simple Mathematics" example from the GH SDK a bit, to have the Degrees modifier available there.

One thing that I noticed is that the tangent of 0.5*Pi does return a value, which it shouldn't. The regular Tangent component does that too...

I attached two versions, in the second I fixed the rule for the tangent. Hope I got it right.

I still think it would be useful if the modifier could be available for outputs too, but haven't found a way yet. Maybe there isn't, and I should stop struggling with that;) I haven't read up on casting yet to find out if that would provide a way.

Attachments:

There's no way to exactly specify 0.5*Pi using 64-bit floating point numbers. Tangent is only undefined for exact values of 0.5*Pi +/- Pi, so you'll never be able to get an actual failed result.

--

David Rutten

david@mcneel.com

True, I understand it now, thanks for explaining that fact:)

Hi everyone,
I'm back at this subject, and would like to supply a different default value for the angle when using degrees, effectively keeping the default angle the same.

In short, for instance: If I use radians the default should be Math.Pi/6, when I use degrees the default should be 30.

Is there anyone who can tell me if this possible (or maybe why I shouldn't do this~), and if so, how to achieve this (preferrably in VB)?

This is obviously(?) not for the SinCosTan component I posted here earlier, but for an angle tolerance setting in a new component.

That is very problematic. Angles are unitless values in GH and whether they get treated as radians or degrees is purely contextual. I'm planning to add an Angle data type to GH2 which means that the angle itself knows whether it's defined in radians or degrees, but until that happens it will be very awkward trying to deal with what you describe.

Thanks for your answer David, Jimmy heard you, moving on :) Cheers

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service