Author Topic: 3DFACE IntersectWith method  (Read 12532 times)

0 Members and 1 Guest are viewing this topic.

LE3

  • Guest
Re: 3DFACE IntersectWith method
« Reply #15 on: January 27, 2011, 11:19:07 AM »
Very mickey mouse help but glad that helps :)
Thanks Swift!

That's some good work Luis!

LE3

  • Guest
Re: 3DFACE IntersectWith method
« Reply #16 on: January 27, 2011, 11:29:52 AM »
Hola Sofito_Soft,
Interesante lo que muestras en las imagenes que subiste, y que lo haces mediante autolisp, muy bien!

Nice, stuff you did and more when can be done via lisp, good!

Saludos.
Luis.



Code: [Select]
(DEFUN INTER_3DCARA_PLANO (ENT     A      B       C        D      /
    LISTA-INTER      N        LISTA-LINEA     TRIAN    INT1
       TOLER-IGUAL
I hope to help you.
Regards from Madrid.

Odoshi

  • Guest
Re: 3DFACE IntersectWith method
« Reply #17 on: January 27, 2011, 03:27:53 PM »
Actually, I am still not getting the desired results.

In your picture, which color is face1 and face2? Then I will know which is extended.

Thanks,
Mike

Good, I have used a lot the intersectWith method in arx, c# and in my vlisp days, but zero about the usage of a plane as argument, nor with 3d faces... so got the chance to learn too. :)

Cheers,
Luis.

Yes, that's the ticket. Thanks for your help!

LE3

  • Guest
Re: 3DFACE IntersectWith method
« Reply #18 on: January 27, 2011, 03:52:02 PM »
Here it goes my code and an animated image - yellow 3d face first - red in second:
Code: [Select]
[CommandMethod("INTF", CommandFlags.Modal)]
public void cmd_intersFaces()
{
    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;

    PromptEntityOptions peo = new PromptEntityOptions("");
    peo.Message = "\n<Enter to exit>/Select first 3d face (to project)";
    peo.SetRejectMessage("\n***Object must be a 3d face. \n");
    peo.AddAllowedClass(typeof(Face), true);
    peo.AllowNone = true;
    PromptEntityResult per1 = ed.GetEntity(peo);
    if (per1.Status != PromptStatus.OK) return;

    peo.Message = "\n<Enter to exit>/Select second 3d face (projection plane)";
    PromptEntityResult per2 = ed.GetEntity(peo);
    if (per2.Status != PromptStatus.OK) return;

    Point3dCollection points = new Point3dCollection();

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false) as BlockTableRecord;

        Face face1 = tr.GetObject(per1.ObjectId, OpenMode.ForWrite, false) as Face;
        Face face2 = tr.GetObject(per2.ObjectId, OpenMode.ForWrite, false) as Face;

        Plane projectionPlane = new Plane();
        Matrix3d ucsMatrix = ed.CurrentUserCoordinateSystem;
        CoordinateSystem3d ucs = new CoordinateSystem3d();
        ucs = ucsMatrix.CoordinateSystem3d;

        projectionPlane = new Plane(face2.GetVertexAt(0), ucs.Xaxis, ucs.Yaxis);
        face1.IntersectWith(face2, Intersect.OnBothOperands, projectionPlane, points, 0, 0);

        #region debug print message and points
        ed.WriteMessage("\nPoints count: {0} \n", points.Count.ToString());
        foreach (Point3d pt in points)
        {
            DBPoint point = new DBPoint();
            point.Position = pt;
            btr.AppendEntity(point);
            tr.AddNewlyCreatedDBObject(point, true);
        }
        #endregion

        tr.Commit();
    }
}
« Last Edit: January 27, 2011, 05:49:13 PM by LE »

LE3

  • Guest
Re: 3DFACE IntersectWith method
« Reply #19 on: January 27, 2011, 05:54:14 PM »
Ok... I did some corrections, this one works on all the cases.

INTF = if does not find the intersection, select the faces in inverse sequence.
INTF2 = works in all cases.

Let me know if works for you.

edit: removed extraction of vertex 4 not required.
Code: [Select]
[CommandMethod("INTF", CommandFlags.Modal)]
public void cmd_intersFaces()
{
    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;

    PromptEntityOptions peo = new PromptEntityOptions("");
    peo.Message = "\n<Enter to exit>/Select first 3d face (to project)";
    peo.SetRejectMessage("\n***Object must be a 3d face. \n");
    peo.AddAllowedClass(typeof(Face), true);
    peo.AllowNone = true;
    PromptEntityResult per1 = ed.GetEntity(peo);
    if (per1.Status != PromptStatus.OK) return;

    peo.Message = "\n<Enter to exit>/Select second 3d face (projection plane)";
    PromptEntityResult per2 = ed.GetEntity(peo);
    if (per2.Status != PromptStatus.OK) return;

    Point3dCollection points = new Point3dCollection();

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false) as BlockTableRecord;

        Face faceProject = tr.GetObject(per1.ObjectId, OpenMode.ForWrite, false) as Face;
        Face facePlane = tr.GetObject(per2.ObjectId, OpenMode.ForWrite, false) as Face;

        Point3d p1, p2, p3;
        p1 = facePlane.GetVertexAt(0);
        p2 = facePlane.GetVertexAt(1);
        p3 = facePlane.GetVertexAt(2);
        Vector3d vU = p2.GetAsVector() - p1.GetAsVector();
        Vector3d vV = p3.GetAsVector() - p1.GetAsVector();
        Plane projectionPlane = new Plane(p1, vU, vV);

        facePlane.IntersectWith(faceProject, Intersect.ExtendArgument, projectionPlane, points, 0, 0);

        #region debug print message and points
        ed.WriteMessage("\nPoints count: {0} \n", points.Count.ToString());
        foreach (Point3d pt in points)
        {
            DBPoint point = new DBPoint();
            point.Position = pt;
            btr.AppendEntity(point);
            tr.AddNewlyCreatedDBObject(point, true);
        }
        #endregion

        tr.Commit();
    }
}

[CommandMethod("INTF2", CommandFlags.Modal)]
public void cmd_intersFaces2()
{
    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;

    PromptEntityOptions peo = new PromptEntityOptions("");
    peo.Message = "\n<Enter to exit>/Select first 3d face (to project)";
    peo.SetRejectMessage("\n***Object must be a 3d face. \n");
    peo.AddAllowedClass(typeof(Face), true);
    peo.AllowNone = true;
    PromptEntityResult per1 = ed.GetEntity(peo);
    if (per1.Status != PromptStatus.OK) return;

    peo.Message = "\n<Enter to exit>/Select second 3d face (projection plane)";
    PromptEntityResult per2 = ed.GetEntity(peo);
    if (per2.Status != PromptStatus.OK) return;

    Point3dCollection points = new Point3dCollection();

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false) as BlockTableRecord;

        Face faceProject = tr.GetObject(per1.ObjectId, OpenMode.ForWrite, false) as Face;
        Face facePlane = tr.GetObject(per2.ObjectId, OpenMode.ForWrite, false) as Face;

        Point3d p1, p2, p3;
        p1 = facePlane.GetVertexAt(0);
        p2 = facePlane.GetVertexAt(1);
        p3 = facePlane.GetVertexAt(2);
        Vector3d vU = p2.GetAsVector() - p1.GetAsVector();
        Vector3d vV = p3.GetAsVector() - p1.GetAsVector();
        Plane projectionPlane = new Plane(p1, vU, vV);

        facePlane.IntersectWith(faceProject, Intersect.ExtendArgument, projectionPlane, points, 0, 0);

        if (points.Count == 0)
        {
            p1 = faceProject.GetVertexAt(0);
            p2 = faceProject.GetVertexAt(1);
            p3 = faceProject.GetVertexAt(2);            
            vU = p2.GetAsVector() - p1.GetAsVector();
            vV = p3.GetAsVector() - p1.GetAsVector();
            projectionPlane = new Plane(p1, vU, vV);
            faceProject.IntersectWith(facePlane, Intersect.ExtendArgument, projectionPlane, points, 0, 0);
        }

        #region debug print message and points
        ed.WriteMessage("\nPoints count: {0} \n", points.Count.ToString());
        foreach (Point3d pt in points)
        {
            DBPoint point = new DBPoint();
            point.Position = pt;
            btr.AppendEntity(point);
            tr.AddNewlyCreatedDBObject(point, true);
        }
        #endregion

        tr.Commit();
    }
}
« Last Edit: January 29, 2011, 12:25:45 AM by LE »

Odoshi

  • Guest
Re: 3DFACE IntersectWith method
« Reply #20 on: February 01, 2011, 05:55:11 AM »
I've got it working now. My faces had 3 visible points, not 4, and calc'ing the normal is a little different. Also, since my intersecting planes were always with a Z-axis normal, I was able to figure out the projection plane.

Thanks for all your help,
Mike