Grasshopper

algorithmic modeling for Rhino

Hi
had trouble understanding how to get the area of curve - found an example for a brep volume in the primer but it seems to work differently than for curves
I did the following:

For Each crv As oncurve In x
Dim centroid As New on3dpoint
Dim normal As New On3dVector
Dim cMass As New OnMassProperties
Dim area As New Double
crv.AreaMassProperties(centroid, normal, cMass)
area = cMass.Area()
print(area)
Next

but the areas are coming out as 0...

I feel like it's because I need to be giving the centre and normal vectors but I don't know these offhand - I assumed that these sorts of things are generated by the method. Any ideas?

Views: 1928

Replies to This Discussion

I've got no idea why the area calculation is slightly different to one generated by a component (or Rhino caclulation) - it's also the same for a surface VB area calc.
I've set up a basepoint at the start of the curve and used a static z vector as a plane input.

Sub RunScript(ByVal inCrv As OnCurve)
Dim tol As Double = RhUtil.RhinoApp().ActiveDoc().AbsoluteTolerance()

Dim bBox As New OnBoundingBox
inCrv.GetBoundingBox(bBox)

Dim bPt As New On3dPoint
bPt = inCrv.PointAt(0)

Dim normal As New On3dVector(0, 0, 1)
Dim cMass As New OnMassProperties
Dim area As New Double
inCrv.AreaMassProperties(bPt, normal, cMass, Nothing, Nothing, tol)
area = cMass.Area()

A = area
End Sub
Dirk solution is good. the one thing I would change is to use bBox.Center() as "Center" point for the AreaMassProperty method.
Also, if input curves are on world xy_plane, then using zaxis as "Normal" is appropriate, otherwise I woud find curve plane and use the plane normal instead.
Sorry... yep, the BBox was a test to check if the area calcs were different. Rajaa, would you know why the area calcs differ between (Rhino or GH Area Component) and (VB area calculation)?
Hi Dirk,
Can you send me a sample file with curves and sample code you used to compare?
Rajaa, thanks very much for looking at this :D
Attachments:
Hi Dirk,
Sorry it took sometime to get back to you.

We found a bug in the low level curve area calculation in some special cases. This will be fixed. For now, please use the attached work around to get accurate result.

Thanks for your report.
Attachments:
Thanks Rajaa.

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service