algorithmic modeling for Rhino
Which convex hull function?
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Oh sorry, you meant the 2D convex hull that ships with Grasshopper! I was confused and thought you wanted 3D convex hulls.
Have a look at the Grasshopper.Kernel.Geometry.ConvexHull namespace. There's a Solver class in there that has static methods for solving hulls.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Yes, 2d points. I couldn't find what you said in the Grasshopper SDK. Any thoughts on how to actually write this. I have a list of points say
PList as new list (of point3d) and I want the hull for them (the Z unit is 0 for all points)
Dim nodes As New Grasshopper.Kernel.Geometry.Node2List(pts)
A = Grasshopper.Kernel.Geometry.ConvexHull.Solver.ComputeHull(nodes)
If pts is a List of Point3d, then the above will work.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
It worked, thanks a lot ! I was writing the convex hull algorithm myself, but this saves me some time.
This isn't in the SDK is it? The grasshopper.kernel.geometry.etc ..
Anyway, thank you again.
Cheers
If it wasn't in the SDK you couldn't use it. But the Grasshopper.Kernel.Geometry namespace is omitted from the SDK helpfile.
In fact a lot of stuff is omitted from the helpfile, either because I felt it was pointless to anyone but me or because I never took the time to write decent comments. In this case because of the latter.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Sorry one more question.
Say I get the convex hull, now I need the area centroid or center of gravity for the hull.
I am really sorry for asking these questions but I need this to drive my algorithm.
I was thinking of making a planar surface out of the polyline hull and then just evaluating the surface at surface parameter (0.5, 0.5).
Thanks in advance.
You can use Rhino.Geometry.AreaMassProperties to find the centroid of your hull. But first you'll need to convert it from a Polyline into a class that derives from the abstract Curve class:
Dim nodes As New Geometry.Node2List(pts)
Dim hull As Polyline = ConvexHull.Solver.ComputeHull(nodes)
Dim am As AreaMassProperties
am = AreaMassProperties.Compute(new PolylineCurve(hull))
Dim pt As Point3d = am.Centroid
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hey, I've tried your code and it works, but when I put it in a function
I get "object reference not set to an instance of an object". The function returns the hull center. Here's the code
Function get_HullCenter(ByVal _PPList As list (Of PtPointer)) As point3d
Dim i As Integer
Dim newList As New list(Of Point3d)
For i = 0 To _PPList.count - 1
newList.add(_PPList(i).getPoint)
Next
If newList.count = 1 Then 'test if the list has one or two points and return hullcenter
Return newList(0)
Else
If newList.count = 2 Then
Dim v1 As New vector3d(newList(0))
Dim v2 As New vector3d(newList(1))
Dim _pt As New point3d((v1.X + v2.X) / 2, (v1.Y + v2.Y) / 2, (v1.Z + v2.Z) / 2)
Return _pt
End If
End If
Dim nodes As New Grasshopper.Kernel.Geometry.Node2List(newList) 'get hullcenter for 3 or more points
Dim _crv As polyline = Grasshopper.Kernel.Geometry.ConvexHull.Solver.ComputeHull(nodes)
Dim am As AreaMassProperties
am = AreaMassProperties.Compute(New PolylineCurve(_crv))
Dim pt As point3d = am.Centroid
Return pt
End Function
Help !
Sorry one more question.
Say I get the convex hull, now I need the area centroid or center of gravity for the hull.
I am really sorry for asking these questions but I need this to drive my algorithm.
I was thinking of making a planar surface out of the polyline hull and then just evaluating the surface at surface parameter (0.5, 0.5).
Thanks in advance.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by