C# get z-value from 3dFace according to coordinates

Hi,

I want to write a routine that determines the z-value of any given point according to the x and y values. Any pointes in the right direction would be highly appreciated.

Thanks!

Comments

  • Do you just want to prompt the user to enter a point and enter the coordinate into the command line? You can simply watch the pointer point in the BricsCAD status bar. Why do you need a program?
    Indicate in which language you are programming.

  • please specify your inquiry clearly enough !
    You say that " you want to write a routine that determines the z-value of any given point according to the x and y values"..........
    The Z-value of a point on a 3DFace or on the plane defined by a 3Dface, provided it is a 3Dface defined by 3 points and not 4 points!
    A 4-points 3Dface as a matter of fact defines 2 intersecting planes......................
    And you want it probably in C# .NET ????

  • Yes, I want to write a routine in C#.

    Also, the 3dFace is always defined by three points. If I were to do it manually, I would draw a point with a z-Value of 0 and use projectgeometry for example.

    I've tried to show the problem with a small picture:

  • Terry Dotson
    edited May 2021

    Think of your inside point not as one point, but two, a vertical ray.

    TopPnt = 75,151,200
    BotPnt = 75,151,50

    Create a LineSegment3d (the ray) using those points.
    Create a BoundedPlane using the triangle coordinates.

    BndPln.IntersectWith(RayObj) returns an array of Point3D,
    if it's length is 1 element it's the intersection point.

  • By clicking a point on the XY Plane, you get always a 3D Point on the 3DFACE plane in UCS coordinates
    Try the code below :

            [CommandMethod("L3DFIntersection", CommandFlags.UsePickSet)]
            public void GetL3DFIntersection()
            {
                // just some settings to get the 3D intersection point in the form  (68768.76, 67637.67, 67.78)
                System.Globalization.CultureInfo customCulture =
                    (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
                customCulture.NumberFormat.NumberDecimalSeparator = ".";
                customCulture.NumberFormat.CurrencyDecimalSeparator = ".";
                System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
    
                // Obtain the necessary objects, Database, editor and transaction
                Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
                Database db = HostApplicationServices.WorkingDatabase;
                Editor ed = doc.Editor;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    PromptEntityOptions prEntOpt = new PromptEntityOptions("\nSelect a 3DFACE:");
                    prEntOpt.SetRejectMessage("\nMust be a 3DFACE.");
                    prEntOpt.AddAllowedClass(typeof(_AcDb.Face), true);
                    PromptEntityResult prEntRes = ed.GetEntity(prEntOpt);
                    PromptPointResult ptRes = ed.GetPoint("Select a Point :");
    
                    _AcDb.Face faceEnt = tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead) as _AcDb.Face;
    
                    var cs = faceEnt.GetPlane().GetCoordinateSystem();
                    var o = cs.Origin;
                    var x = cs.Xaxis;
                    var y = cs.Yaxis;
                    var pl = new Plane(o, x, y);
    
                    Line3d l3d = new Line3d(ptRes.Value, ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis);
                    Point3d[] iPt = l3d.IntersectWith(pl);
    
                    ed.WriteMessage("\n Intersection Point : {0}", iPt[0]);
                    tr.Commit();
                }
            }