Grasshopper

algorithmic modeling for Rhino

hey guys,

I'm having a really difficult time rewriting the legacy vb code in the attached file to c# with the new SDK.

I think i may have hit some bugs.. ?.

 

Views: 413

Attachments:

Replies to This Discussion

Looking though this code now. I see at least one bug so far:

crv.Domain.Set(0, 1);

this line of code does nothing.

Domain is of type Rhino.Geometry.Interval, which is a ValueType. I.e. when you call crv.Domain you get a copy of the domain. You then proceed to modify this copy. This is different from the old SDK where ON_Interval was a class (reference type), not a value type.

Write this instead:

crv.Domain = new Interval(0, 1);

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Also, when you create your NurbsCurves, I don't think you want to create periodic curves:

Rhino.Geometry.NurbsCurve.Create(true, 2, cPts);

I think you want to use false as the first argument.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
yep, thanks david..

i debugged everything but even though the code has the same structure i am getting a different result, if you have a minute could you take a look, because i feel like its some fundamental logic difference between the old sdk and the new.

thanks
Attachments:
I'm not entirely certain what the algorithm is supposed to do, but I rewrote the script as I would have written it. It seems to generate smooth curves, though I don't know if this is what you are looking for.

Do note that you switched SDKs and programming languages at the same time. I'm not at all certain some of the loops have been translated from VB to C# correctly.

Another thing to watch out for is the different division behaviour in VB and C#:

Dim A As Int32 = 50
Dim B As Int32 = 8
Print("A/B = {0}", A / B)


will yield "A/B = 6.25", whereas:

int A = 50;
int B = 8;
Print("A/B = {0}", A / B);


will yield "A/B = 6"


In C#, when you divide two integers, the result will be an integer. In VB, the result is a double.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Attachments:
perfect, thanks a lot david.

curious, is it possible to redraw in .net.

if not, might it be possible to add a progress bar..?

thanks again
Problem is that if the script crashes, the feedback form is not properly destroyed. You should probably add a try...catch...finally clause around the script ensuring form destruction.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Attachments:
But how to reparameterize a surface with VB?

The srf.domain(int) is a function not a Property of a surface,you can't write something like
srf.domain(0)=new Interval(0, 1);

best,
Hi,

I asked David this yesterday, I haven't validated yet, but
srf.SetDomain(0,new Interval(0,1));
srf.SetDomain(1,new Interval(0,1));

should accomplish this.

Cheers,

Jon
srf.SetDomain(1, New Interval(0, 1))

I would have preferred two properties on Surfaces (UDomain and VDomain respectively), but we've got a single get and set method now that takes an integer for the direction.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi guys,
I been looking at this code as well and I seem to have hard time understanding why the following lines of codes makes a big difference on the final outcome.

If dist_local < dist Then
motion = pt - cv(i)
dist = dist_local
End If

I have print out dist and realize its a huge number that dist_local cannot be greater than...so can someone how this work logically?
< means smaller than, not larger than.

dist is set to the biggest possible number before we start, so we know that every distance we calculate will be smaller than the initial value. This way we can guarantee that we indeed found the smallest distance.

Let's assume the distance calculation (stored in dist_local) in our loop would return the following results: 35.9, 40.5, 33.3, 80.2, 22.4, 3.7

When this loop starts dist will be equal to 1.7977e+308 which is the highest possible number in computing. Then, as the loop runs, we get the following:

iteration | dist_local |         logic                  | dist
    0          35.9      35.9 is less than 1.7977e+308    35.9
    1          40.5      40.5 is not less than 35.9       35.9
    2          33.3      33.3 is less than 35.9           33.3
    3          80.2      80.2 is not less than 33.3       33.3
    4          22.4      22.4 is less than 33.3           22.4
    5           3.7       3.7 is less than 22.4            3.7


--
David Rutten
david@mcneel.com
Poprad, Slovakia
thanks david, this really helps

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