Author Topic: Autocad 3dSolid MassProperties Principal Axes  (Read 2053 times)

0 Members and 1 Guest are viewing this topic.

GRH

  • Mosquito
  • Posts: 6
Autocad 3dSolid MassProperties Principal Axes
« on: May 25, 2016, 04:01:07 AM »
Hi,

I am working on a project to compare Autocad solids for geometry equality..

At the moment I'm only testing solids that are extrusions from closed 2d polyline.

so the basic concept is collect points from the solid entity(using Explode x2), add them to my point collection, then check collections for equality.

the question is, how is the principal axes calculated for solids? I need to know this to transform each solid to the same coordinates to compare.

see the code below..... this seems to work except some solids end up exactly 180 deg out around the WCS z axis?

Is there a better approach besides using the mass properties to get a solids ECS/OCS? (Brep api is a little over my head ATM)

any help would be appreciated.

Code - Visual Basic: [Select]
  1.         <CommandMethod("InvertECS")> _
  2.         Public Sub InvertECS()
  3.  
  4.             Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  5.             Dim db As Database = doc.Database
  6.             Dim ed As Editor = doc.Editor
  7.  
  8.             'pick the solid
  9.            Dim peo As New PromptEntityOptions(vbLf & "Select a 3D solid: ")
  10.             peo.SetRejectMessage(vbLf & "Invalid selection...")
  11.             peo.AddAllowedClass(GetType(Solid3d), True)
  12.  
  13.             Dim per As PromptEntityResult = ed.GetEntity(peo)
  14.  
  15.             If per.Status <> PromptStatus.OK Then
  16.                 Return
  17.             End If
  18.  
  19.             Dim Id As ObjectId = per.ObjectId
  20.  
  21.             'start transaction
  22.            Using Tr As Transaction = db.TransactionManager.StartTransaction()
  23.  
  24.                 'get the solid
  25.                Dim sol As Solid3d = DirectCast(Tr.GetObject(Id, OpenMode.ForWrite), Solid3d)
  26.  
  27.                 'get the solid mass properties
  28.                Dim mprops As Solid3dMassProperties = sol.MassProperties
  29.                 Dim origin As Point3d = mprops.Centroid
  30.                 Dim solX As Vector3d = mprops.PrincipalAxes(0)
  31.                 Dim solY As Vector3d = mprops.PrincipalAxes(1)
  32.                 Dim solZ As Vector3d = mprops.PrincipalAxes(2)
  33.  
  34.                 'entity coordinate system from mass properties
  35.                Dim ECS As New CoordinateSystem3d(origin, solX, solY)
  36.  
  37.                 'world coordinate system
  38.                Dim WCS As New CoordinateSystem3d(New Point3d(0, 0, 0), New Vector3d(1, 0, 0), New Vector3d(0, 1, 0))
  39.  
  40.                 'transformation matrix
  41.                Dim TrMatrix As New Matrix3d()
  42.  
  43.                 TrMatrix = Matrix3d.AlignCoordinateSystem(ECS.Origin, _
  44.                                                           ECS.Xaxis, _
  45.                                                           ECS.Yaxis, _
  46.                                                           ECS.Zaxis, _
  47.                                                           WCS.Origin, _
  48.                                                           WCS.Xaxis, _
  49.                                                           WCS.Yaxis, _
  50.                                                           WCS.Zaxis)
  51.                 'transform the solid
  52.                sol.TransformBy(TrMatrix)
  53.  
  54.                 'save for now to check results
  55.                Tr.Commit()
  56.  
  57.             End Using
  58.         End Sub
  59.  
  60.  

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1379
  • class keyThumper<T>:ILazy<T>
Re: Autocad 3dSolid MassProperties Principal Axes
« Reply #1 on: May 25, 2016, 04:32:08 AM »
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

SEANT

  • Bull Frog
  • Posts: 338
Re: Autocad 3dSolid MassProperties Principal Axes
« Reply #2 on: May 25, 2016, 04:37:14 AM »

..... this seems to work except some solids end up exactly 180 deg out around the WCS z axis?

. . . .

PrincipalDirection analysis does help with Pitch and Yaw, but does leave ambiguity to Roll.*

The principal direction could also help to generate a cross section.*  That section (Region) could be analyzed as well.  Its Principal direction and/or longest linear member, in relation to its centroid, would help with the roll orientation.

I looked at this process with VBA in this thread:
https://www.theswamp.org/index.php?topic=21524.msg260549#msg260549
 


*I should point out, though, that PrincipalDirection only works directly for Pitch and Yaw if the 3dSolid extrusion is without any Boolean/Slice operations.

Sean Tessier
AutoCAD 2016 Mechanical

dgorsman

  • Water Moccasin
  • Posts: 2430
Re: Autocad 3dSolid MassProperties Principal Axes
« Reply #3 on: May 25, 2016, 10:20:20 AM »
Wouldn't an interference operation be easier?  If they are the same the result will be nothing; the closer they are to each other the smaller the volume of the result.  Even simpler (although only useful for a go/nogo test) would be comparing bounding boxes - if the min/max of the two boxes are NOT identical the shapes cannot be identical.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

MickD

  • Gator
  • Posts: 3435
  • (x-in)->[process]->(y-out)
Re: Autocad 3dSolid MassProperties Principal Axes
« Reply #4 on: May 25, 2016, 05:40:33 PM »
The easiest way to handle transformations I have found is to add a World Space (1013) 3d point to the entity as xdata. You add this at 3d solid creation time as your primary axis.
Example: you store the extrusion axis (the normal from the 2d polyline to extrude).

This xdata is updated with rotations, mirroring etc and is reliable, just invert this coordinate to WCS and do your comparisons. I'd use the Brep library and leverage the Equals method for each type of Brep entity for an accurate comparison.
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.

GRH

  • Mosquito
  • Posts: 6
Re: Autocad 3dSolid MassProperties Principal Axes
« Reply #5 on: May 26, 2016, 12:43:06 AM »
Awesome, thanks for the replies....

Wouldn't an interference operation be easier?

Yes, and this is similar to one of my sanity checks, I use volume property though. the geometry check is the hardest and most expensive, that's why it is the last check I do (if all else fails) to know with absolute certainty that the objects are different.

I've also looked at the bounding box / extents check but before now I couldn't rely on it as always seems to align to WCS xy plane (no good for objects rotated in 3d), I spose I could use that now as I can transform to WCS 0,0,0 and do the extents check there.

Do you know if there is like a "shrink wrap" (tight bounding box) example anywhere?


*I should point out, though, that PrincipalDirection only works directly for Pitch and Yaw if the 3dSolid extrusion is without any Boolean/Slice operations.

Thanks for the links, very interesting and not unlike the approach I had in mind.

My approach was to disassemble the solid using Brep and compare the faces for equality. Finding 2 identical parallel  faces might indicate extrusion direction (assuming for now, no mods).

I'm still confused as to why there is no reference made to the WCS or a vector describing the extrusion direction, at creation time? surely this is an inexpensive property and would do away with guess game later.


The easiest way to handle transformations I have found is to add a World Space (1013) 3d point to the entity as xdata.

Thanks Mick, that's exactly what I've done, however I still need to deal with solids that have been created prior.

GRH