Author Topic: Matrix3d and TransformBy help  (Read 25381 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Matrix3d and TransformBy help
« on: July 21, 2008, 08:21:37 AM »
what I am trying to do is get the bounding box of my cuboid by getting the longest edge from the solid,
using the points from the edge create a matrix to align the solid to the WCS,  then getting the bounding box. 
My method is soo ugly, I wonder if one of you 3D guys might help me find a better solution. Acad09 w/brep

Code: [Select]

removed junk code

« Last Edit: July 21, 2008, 03:02:27 PM by Daniel »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #1 on: July 21, 2008, 08:33:59 AM »

Here is a picy of a sample object I would like to align to the WCS

SEANT

  • Bull Frog
  • Posts: 324
Re: Matrix3d and TransformBy help
« Reply #2 on: July 21, 2008, 09:15:29 AM »
what I am trying to do is get the bounding box of my cuboid by getting the longest edge from the solid,
using the points from the edge create a matrix to align the solid to the WCS,  then getting the bounding box. 
My method is soo ugly, I wonder if one of you 3D guys might help me find a better solution. Acad09 w/brep

You may think it ugly, but I think it pretty effective.  I'll be watching this thread with interest.
Sean Tessier
AutoCAD 2016 Mechanical

SEANT

  • Bull Frog
  • Posts: 324
Re: Matrix3d and TransformBy help
« Reply #3 on: July 21, 2008, 10:40:37 AM »
Would the next general step be to backtrack from that longest edge to the Parent’s (or is it the Child’s) face with the largest area?  Perhaps use that face’s Normal as a guide to square up the remaining axis.  This “roll” axis, as was discussed in some similar VBA threads, seems to be particularly difficult to orient. 
Sean Tessier
AutoCAD 2016 Mechanical

ahlzl

  • Guest
Re: Matrix3d and TransformBy help
« Reply #4 on: July 21, 2008, 11:08:49 AM »
I don't completely understand.

NO Brep
Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace MyUCS
{
    public class Class1
    {
        [CommandMethod("test")]
        public void MyTest()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            Matrix3d mt = ed.CurrentUserCoordinateSystem;

            PromptEntityOptions opt = new PromptEntityOptions("\nSelect...");
            PromptEntityResult res = ed.GetEntity(opt);

            if (res.Status == PromptStatus.OK)
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    Entity ent = (Entity)trans.GetObject(res.ObjectId,
                        OpenMode.ForWrite);
                    ent.TransformBy(mt.Inverse());
                    Point3d maxPt = ent.GeometricExtents.MaxPoint;
                    Point3d minPt = ent.GeometricExtents.MinPoint;
                    ent.TransformBy(mt);
                    ed.WriteMessage("\n MAX: " + maxPt.ToString());
                    ed.WriteMessage("\n MIN: " + minPt.ToString());       
                    trans.Commit();
                }
            }
        }
    }
}


It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #5 on: July 21, 2008, 11:17:54 AM »
Would the next general step be to backtrack from that longest edge to the Parent’s (or is it the Child’s) face with the largest area?  Perhaps use that face’s Normal as a guide to square up the remaining axis.  This “roll” axis, as was discussed in some similar VBA threads, seems to be particularly difficult to orient. 

Interesting, I will have to try that.

« Last Edit: July 21, 2008, 12:17:52 PM by Daniel »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #6 on: July 21, 2008, 11:25:31 AM »
I don't completely understand.

You would get an incorrect value if your object is rotated off the UCS, for example your routine returns

Quote
TEST
Select...:
(102,2438,50.8 ) width, height, depth
Command:
TEST
Select...:
(1759.84735701708,1759.84735701708,102) width, height, depth

On these objects


« Last Edit: July 22, 2008, 04:43:43 AM by Daniel »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #7 on: July 21, 2008, 12:03:53 PM »
Nope .. needs more work.   :ugly:
Here is the latest code and a test DWG if anyone wants to play. The value should be ( 102,2438,50.8 ) in all cases

Code: [Select]
removed junk code

« Last Edit: July 21, 2008, 03:02:50 PM by Daniel »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #8 on: July 21, 2008, 03:08:53 PM »
Ok I think the attached code works better  :laugh:

edit: made some minor changes

« Last Edit: July 22, 2008, 12:42:25 AM by Daniel »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #9 on: July 22, 2008, 04:31:48 AM »

PFC, now I can extract my cabinet part dimensions, of course this is assuming the parts are not directional (grained)  8-)



bikelink

  • Guest
Re: Matrix3d and TransformBy help
« Reply #10 on: July 22, 2008, 05:20:59 AM »
that's very nice!

SEANT

  • Bull Frog
  • Posts: 324
Re: Matrix3d and TransformBy help
« Reply #11 on: July 22, 2008, 07:20:07 AM »
Daniel,

Excellent, excellent, excellent.

I'm not anywhere near up to speed enough (especially with the BREP stuff) to offer much coding feedback.  I can, however, attempt to throw a wrench, or two, into the works with these sample solids.  Granted, they are not typical, but any ideas on how to account for them?
Sean Tessier
AutoCAD 2016 Mechanical

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #12 on: July 22, 2008, 12:48:40 PM »
Sean, I was able to modify the code to get the I-beam to come through, but the second object may take a little more work. As of now the test is looking for two edges that share a common point and that are perpendicular.  I have attached the latest code (kludge) , unfortunately it seems to spit the dummy when processing large numbers of objects( +4000) .  I dunno why  :-o


Paul Richardson

  • Guest
Re: Matrix3d and TransformBy help
« Reply #13 on: July 22, 2008, 07:22:38 PM »
This just looks for the longest edge in each solid for a test. See attached brep.dwg to see a solid with multiple Complexes and the file TimberData.csv for the results.

See notes in Commands.cs. Code crashes randomly when looping 'brep.Complexes'. Seems to happen more as the number of solids increases - anyone know why?

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6931
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #14 on: July 23, 2008, 12:41:13 AM »
This just looks for the longest edge in each solid for a test. See attached brep.dwg to see a solid with multiple Complexes and the file TimberData.csv for the results.

See notes in Commands.cs. Code crashes randomly when looping 'brep.Complexes'. Seems to happen more as the number of solids increases - anyone know why?

Nice work Paul. Thanks for sharing!
So far I am finding the brep stuff slightly unstable too, no error messages, just poof.