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

0 Members and 1 Guest are viewing this topic.

m.araujo

  • Guest
Re: Matrix3d and TransformBy help
« Reply #30 on: July 24, 2008, 06:14:56 PM »
Quote

Matt, I have compiled my routine for you to try. Some info for you, the routine searches for two edges in the solid that are perpendicular and share a common point, starting with the longest edge then iterating through until a match is found. If a match is found, the data from the edges is used to align the solid with the WCS; the routine then gets the bounding box data. Caveat,  It would be possible for the routine to pickup edges on say a compound miter and return incorrect dimensions.

Give it a shot, the command is Timber, you can find the DLL in the release folder of the attached solution





Daniel,

Thanks.  I will take a look at this code this weekend when I can sit down and study it.  As far as aligning ucs this might be a more fool proof way....I'm way to green to try and code this but this is the method I discovered

run MASSPROP on an object and take note of the I and J coordinates (actually any two of the I,J,K  directions about centroid will work, because there are three appropriate ucs orientations to create the necessary bounding box.  )  create a new ucs with an origin at 0,0,0 and use the I coordinates to define X and the J to define a point on the XY axis....boom, new UCS.  If you then rerun massprop and create a box with an origin of the minimum xyz coord and end at the max xyz coord You will have a oriented bounding box. Of course with this info you don't even need to create the box,  Look at the 2 bounding box coords - subtract the max X value from the min x value, the max y from the min y and so forth....and these need to be |absolute|  values as dimensions cant be negative. 


Thanks again,

Matt Araujo

edit: fixed quote tags
« Last Edit: July 24, 2008, 09:15:56 PM by Daniel »

SEANT

  • Bull Frog
  • Posts: 340
Re: Matrix3d and TransformBy help
« Reply #31 on: July 24, 2008, 08:27:11 PM »
The thing with I, J, and K (Principal Directions) is that they are based on the distribution of mass in the solid.  Consequently, the vectors may not line up with the most useful directions if the solid has any irregularities. 

The attached example exaggerates the issue for demonstration purposes.  Compare the Mass Properties with the dimensions.
Sean Tessier
AutoCAD 2016 Mechanical

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #32 on: July 25, 2008, 01:52:06 PM »
This is interesting, I was looking through the DRX SDK help files under Brep, they have a method
Code: [Select]
//Returns the transformation matrix for this BREP object.
Bool  OdBrBrep::getTransformation(OdGeMatrix3d&  xfm ) const

Sure would be nice if AutoCAD had this .... hint hint

Spike Wilbury

  • Guest
Re: Matrix3d and TransformBy help
« Reply #33 on: July 26, 2008, 12:24:00 PM »
This is interesting, I was looking through the DRX SDK help files under Brep, they have a method
Code: [Select]
//Returns the transformation matrix for this BREP object.
Bool  OdBrBrep::getTransformation(OdGeMatrix3d&  xfm ) const

Sure would be nice if AutoCAD had this .... hint hint


Perhaps, the below function could be use for what you guys are doing, and ported to C#, not fully tested, no idea.-

edit: by me change of pRegion to pSolid

Code: [Select]
static void GetSolidBound(void)
{
ads_name ss, ename;
TCHAR* promptPtrs[] = {_T("Select solid object: "), _T("Remove solid object: ")};
resbuf *ssfilter = acutBuildList(RTDXF0, _T("3DSOLID"), RTNONE);
if (acedSSGet(_T("_:S:$"), promptPtrs, NULL, ssfilter, ss) == RTNORM)
{
acutRelRb(ssfilter);
if (acedSSName(ss, 0, ename) != RTNORM)
{
acedSSFree(ss);
return;
}
acedSSFree(ss);
AcDbObjectId objid = AcDbObjectId::kNull;
acdbGetObjectId(objid, ename);
if (objid == AcDbObjectId::kNull) return;
AcDbObjectPointer <AcDbEntity> pSolid(objid, AcDb::kForWrite);
if (pSolid.openStatus() != Acad::eOk) return;
AcBrBrep brep;
brep.set(*(pSolid.object()));
AcBr::ErrorStatus returnValue = AcBr::eOk;

// getBoundBlock = Geometric bounds query.
// Returns the model space bounding box for the current topology object.
// The box is returned as an AcGeBoundBlock3d, with the entire chain of transforms from the object ID array applied.
// The box is instantiated by the caller and passed by reference for getBoundBlock() to (re)set.
AcGeBoundBlock3d bblock;
returnValue = brep.getBoundBlock(bblock);
if (returnValue != AcBr::eOk)
{
acutPrintf(_T("\n***Error in AcBrBrep::getBoundBlock***"));
return;
}
AcGePoint3d min, max;
bblock.getMinMaxPoints(min, max);
acutPrintf(_T("\n Bounding Block lower corner is ("));
acutPrintf(_T("%lf, "), min.x);
acutPrintf(_T("%lf, "), min.y);
acutPrintf(_T("%lf"), min.z);
acutPrintf(_T(")\n"));
acutPrintf(_T("\n Bounding Block upper corner is ("));
acutPrintf(_T("%lf, "), max.x);
acutPrintf(_T("%lf, "), max.y);
acutPrintf(_T("%lf"), max.z);
acutPrintf(_T(")\n"));
}
}
« Last Edit: July 26, 2008, 12:52:37 PM by Luis E. »

MickD

  • Gator
  • Posts: 3441
  • (x-in)->[process]->(y-out)
Re: Matrix3d and TransformBy help
« Reply #34 on: July 26, 2008, 06:48:32 PM »
The problem with solids is that they do not have a 'useful' direction as such as the solid has no real identity (it's not a steel beam or 4x2 say), it's just some direction derived at creation so it could still be meaningless in some cases.
If the solid was an extrusion, that would be a good start though, particularly in construction and similar trades where 'sections' are used of the shelf.

I still find adding the data at creation to be most efficient for me, I can also add data to existing objects if needed but they still lack other useful data such as it's material/grade, mass, std pitch and gauge for example.

If you want to make a quick 'add directional data' to existing solids. I'd probably ask the user to select an edge (or an edge from multiple solids for easier use using brep to highlight each edge say) indicating length direction and use the edge's face normal to construct the xform matrix, this way you will get the correct length even if it's shorter than the width/height. Unless you are sure that all lengths are greater than W/H it's pretty hard to get it right automatically, somewhere the user will need to decide which way is which.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: To attain knowledge, add things
every day; to obtain wisdom, remove things every day.

Spike Wilbury

  • Guest
Re: Matrix3d and TransformBy help
« Reply #35 on: July 26, 2008, 07:55:10 PM »
Thanks Mick,


Makes sense...



About the 3d world, I am in diapers...  :laugh:


I have been playing with the Z principal axe and trying to build an oriented bounding box.... if works, will post here....

MickD

  • Gator
  • Posts: 3441
  • (x-in)->[process]->(y-out)
Re: Matrix3d and TransformBy help
« Reply #36 on: July 26, 2008, 08:30:18 PM »
As was mentioned earlier, the principal directions are produced from the solids' geometry and centre of gravity etc, this changes as the solid is modified so it will/can change the length direction also so I wouldn't spend too much time on it ;)

I have spent a lot of time on this subject and there's no easy way for the reason's I mentioned above, a 3d solid in autocad terms needs to be a simple as possible so it can be used in any discipline to represent what is needed, if they were to fix things like direction vectors it may put a constraint on what can be done with the solid.

Think of 3d solids as a 'base class' in programming terms that simply provides the solid manifold geometry representation of your object (autocad uses the acis modeling engine for the geometry in memory and acad displays it by drawing each edge/face and sending it to the graphics card), you then derive from it to build in discipline specific attributes for your application.
You can do it in 2 ways, custom objects or use extended data and reactors, I prefer the latter as these elements are native to autocad and well tested and really are not that different (extended data takes a little more work to store and retrieve though).
« Last Edit: July 26, 2008, 08:46:50 PM by MickD »
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: To attain knowledge, add things
every day; to obtain wisdom, remove things every day.

Spike Wilbury

  • Guest
Re: Matrix3d and TransformBy help
« Reply #37 on: July 26, 2008, 08:39:42 PM »
10-4

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #38 on: July 27, 2008, 06:37:24 AM »
Nice work guys!

Dan'
instead of using 2 edges, can you grab the longest edge's normal? or maybe one off the edge's face (one of it's owners) to construct a matrix for xform.
Another way too, you don't need a perp edge, just grab any edge and xproduct it to give a perp vector to both edges, you can then square up the matrix by xproducting the new vec with the first edge vec ;)
hth

Thanks for the tips Mick!
Im really not sure I follow you though.  My abbey normal brain can only figure out how to square up the solid when I have two edges that are perpendicular.  Everything else I try seems to miss one axis.  :mrgreen:

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #39 on: July 27, 2008, 06:43:04 AM »
I still find adding the data at creation to be most efficient for me

This is what I do also.

Just having a bit of fun too, this is the farthest I have ever gotten in aligning the BB with the WCS, I know people (including me) have been trying on and off for years.
« Last Edit: July 27, 2008, 06:46:41 AM by Daniel »

SEANT

  • Bull Frog
  • Posts: 340
Re: Matrix3d and TransformBy help
« Reply #40 on: July 27, 2008, 08:39:15 AM »
Mick

As also implied by Luis and Daniel, I think this exercise has its greatest potential as a matter of intellectual curiosity.

With regard to the more practical considerations, I think your assessment makes perfect sense.  Given the potential benefit of imbuing the solid with useful characteristics, such as the ones you mentioned, leveraging an OpenMode.ForWrite to also include orientation data is efficient. 

One pitfall is when dealing with documents from other organizations.  Many of which may not be receptive to outside routines, especially if required to run persistently.   

My perfect scenario would be the development of organization specific routines which allows processing of non-standardized documents, thus avoiding any compliance requirements.  This processing would couple Entities with material data (as derived from Layer, Tables, Xdata, or etc) in an internally consistent fashion.

Dimensional data would also be included in that processing. Asking the user to select the length for a given solid is the most sensible but has a few drawbacks; some of these projects use hundreds of extrusions, the task is somewhat monotonous, and that user is always me.  Given that potential benefit, the exercise straddles the fence between curiosity and practicality.
Sean Tessier
AutoCAD 2016 Mechanical

Spike Wilbury

  • Guest
Re: Matrix3d and TransformBy help
« Reply #41 on: July 27, 2008, 12:38:12 PM »
Well... since this, it is just an exercise for my brain and before I lost the 1/2 brain cell left....

I have the bounding box (min-max aligned or on the solid not the projected ones as my previous arx function)... now what do I needed for? or use them for....  :ugly:

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #42 on: July 27, 2008, 08:08:41 PM »
Well... since this, it is just an exercise for my brain and before I lost the 1/2 brain cell left....

I have the bounding box (min-max aligned or on the solid not the projected ones as my previous arx function)... now what do I needed for? or use them for....  :ugly:

Well, there are many industries that would benefit from having such an animal, example the commercial casework industry deals with mostly square parts. If one could build a library that would generate a bill of materials or data to feed to a sheet optimizer from a 3d drawing, companies might buy it.. ie think ($$$) :angel:

MickD

  • Gator
  • Posts: 3441
  • (x-in)->[process]->(y-out)
Re: Matrix3d and TransformBy help
« Reply #43 on: July 27, 2008, 09:13:36 PM »
DaveW's MillLister does this, he has been using this approach for quite a while now with some success and I think his product is reasonably priced as well, might be worth a look.
The exercise is fun though :)
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: To attain knowledge, add things
every day; to obtain wisdom, remove things every day.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Matrix3d and TransformBy help
« Reply #44 on: July 27, 2008, 09:25:47 PM »
DaveW's MillLister does this, he has been using this approach for quite a while now with some success and I think his product is reasonably priced as well, might be worth a look.
The exercise is fun though :)

True dat