Grasshopper

algorithmic modeling for Rhino

Hi,

i use mesh.IsPointInside(pt, 0.1, false); and it always returns false even when the point is inside. Does anyone from McNeel can assist?

thanks a lot

Thomas

Views: 1307

Replies to This Discussion

is it similar to this?

This has been broken for a while now. I worked around it by using mesh.ClosestPoint and checking whether the dot product of the normal at that point and the vector from the point to the closest point is positive. It's not ideal though, and a working IsPointInside would be much better.

I see what's going on.  The low level implementation for this function was never completed and just returns false.  I added an item to our internal bug tracker to have the developer who works on this complete the function.

In the meantime, I rewrote the IsPointInside function to get the right answer "most" of the time by

  1. Making sure the mesh is solid
  2. Using a line-mesh intersector and counting the number of crossings. The the start of the line is the point to test and the endpoint of the line is out beyond the bounding box of the mesh.  An odd number of crossings means the point is inside. This is how the function will work in the next v5 beta (or next grasshopper release for people using V4).

Thanks,

-Steve

How should I do this intersection ? 

 

Function isPtInside(pt As point3d, msh As mesh) As Boolean
Dim fIdx As int32() = New Int32() {0,0}
Dim isIn As Boolean = False
Dim bbox As New rhino.Geometry.BoundingBox
bbox = msh.GetBoundingBox(True)
Dim fp As New point3d
fp = bbox.FurthestPoint(pt)
Dim vec As New vector3d(fp.X - pt.X, fp.Y - pt.Y, fp.Z - pt.Z)
Dim dist As Double = fp.DistanceTo(pt)
Dim xLine As New Line(pt, vec, dist * 10)
Dim xCrv As New rhino.Geometry.PolylineCurve
xCrv.SetStartPoint(xLine.From)
xCrv.SetEndPoint(xLine.To)


Dim interPt() As point3d = rhino.Geometry.Intersect.Intersection.MeshPolyline(msh, xCrv, fIdx)


If interPt.length mod 2 = 0 then 

isIn = false

else

isIn = true

end if

Return isIn

End Function



This returns an error "Object reference not set to an instance of an object" (I guess that its related to interPt array)

I have to add 2 values (0,0) to fIdx array, otherwise I get a warning that it has no values and it may return a null.

+ you said "Using a line-mesh intersector" ... I cant find it (rhino 4), so I create a polylineCurve to use polyline-mesh intersector. (cant cast line to polyline).. is that how you do it ?

Not really sure where your error is, but this is how I'd write it:

Function IsPointInMesh(ByVal point As Point3d, ByVal mesh As Mesh) As Boolean
  Dim box As BoundingBox = mesh.GetBoundingBox(True)
  If (Not box.Contains(point)) Then Return False

  Dim polyline As New Polyline()
  polyline.Add(point)
  polyline.Add(box.Max + New Vector3d(100, 100, 100))

  Dim x As Point3d() = Intersect.Intersection.MeshPolyline(mesh, _

                                 New PolylineCurve(polyline), Nothing)
  If (x Is Nothing) Then Return False
  Return (x.Length Mod 2) = 1

End Function


--

David Rutten

david@mcneel.com

Poprad, Slovakia

The IsPointInside function should now work if you get the latest V5 beta, since it contains the rewrite I mentioned above.

-Steve

Yes - mesh IsPointInside is working nicely now, as are mesh edge splitting and collapse. Thanks Steve!

Hi Guys,

Any chance of seeing mesh.InPointInside command in a script please as having trouble writing the code

Would be great if we can have it as a component.

Thanks

Matt

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service