70001938 Is there a Point-Inside-Test in a vdPolyhatch

Article 70001938
Type HowTo
Product Engine
Version 8
Date Added 3/11/2021 12:00:00 AM
Fixed 9.9001.0.4 (3/11/2021 12:00:00 AM)
Submitted by Thoms Kohler


I look for a Point-Inside-Test in a vdPolyhatch


This can be done with two ways, one using the isPointInside method of the vdPolyface (after you “transform” the polyhatch to a polyface using ToMesh method) and the other is usinbg GetFilledPolygons method of the polyhatch that will return an array of “gPoints” that you can check using IsPointInside of the gPoints. Preferable is the GetFilledPolygons method. Try the code below (both methods) :

                gPoint pt = null;
                vdFigure fig = null;
                doc.Prompt("Select a Polyhatch");
                doc.ActionUtility.getUserEntity(out fig, out pt);

                gPoint pointTocheck = null;
                doc.Prompt("Pick The point to check");
                StatusCode s = doc.ActionUtility.getUserPoint(out pointTocheck);
                if (s == StatusCode.Success && pointTocheck != null)
                    // First way is to convert the polyhatch into a polyface and then use the isPointInside method of the polyface.
                    // Note that this way can be a little slow depending on how complex is the polyhatch.
                    gPoint pointToCheckWorld = doc.User2WorldMatrix.Transform(pointTocheck);

                    vdPolyhatch hatch = fig as vdPolyhatch;
                    if (hatch == null) return;
                    vdPolyface face = hatch.ToMesh(0);
                    bool ret = face.isPointInside(pointToCheckWorld);

                    //Second way is to use another method of the polyhatch which is GetFilledPolygons
                    bool ret3 = false;
                    vdArray regions = hatch.HatchProperties.GetFilledPolygons(0, 0.0);
                    foreach (gPoints item in regions)
                        if (item.IsPointInside(pointToCheckWorld)) { ret3 = true; break; }

Send comments on this topic.