TransformBy / Mirroring

Discussion in 'AutoCAD' started by Maksim Sestic, Mar 14, 2005.

  1. Dear all,

    Can anyone tell me what transformation matrix do I need to mirror a block around given 3D point (actually block's InsertionPoint)? I read everything available on TransformBy and I still can't apply that one.

    Regards,
    Maksim Sestic
     
    Maksim Sestic, Mar 14, 2005
    #1
  2. Maksim Sestic

    antmjr Guest

    given a transformation matrix:

    A B C D
    E F G H
    I L M N
    0 0 0 1

    the vector AEI defines the direction of the X axis, BLF the direction of the Y axis, CGM the direction of the Z axis and (D,H,N) are the coords of the Origin of your system

    to mirror about the X axis, you simply need to change the signs of the Xs:
    -A -B -C D
    E F G H
    I L M N
    0 0 0 1

    about y:
    A B C D
    -E -F -G H
    I L M N
    0 0 0 1

    about x and y (i.e. to reflect something from the first quadrant XY to the third quadrant -X-Y) :
    -A -B -C D
    -E -F -G H
    I L M N
    0 0 0 1

    TransformBy uses Isotropic matrices; in general, the sum of the squares of the elements of a row or of a column, has to be 1. Hence be aware you have not to round or change the value of some elements of your matrix while changing the signs
     
    antmjr, Mar 14, 2005
    #2
  3. Maksim Sestic

    antmjr Guest

    ehm, sorry. When I wrote

    in general, the sum of the squares of the elements of a row or of a column, has to be 1

    I was thinking to the so called rotation matrix inside the transformation matrix

    A B C
    E F G
    I L M
     
    antmjr, Mar 14, 2005
    #3
  4. Maksim Sestic

    TomD Guest

    I might be ignorant of your motives, but why not use the Mirror method?
    Dear all,

    Can anyone tell me what transformation matrix do I need to mirror a block around given 3D point (actually block's InsertionPoint)? I read everything available on TransformBy and I still can't apply that one.

    Regards,
    Maksim Sestic
     
    TomD, Mar 14, 2005
    #4
  5. Maksim Sestic

    antmjr Guest

    'Maksim, if your blockref Bk lies on the WCS XY plan, the transformation matrix is:
    Const pi½ As Double = 3.14159265358979 / 2
    Dim Bk As AcadBlockReference
    Dim pt As Variant
    Dim r As Double
    Dim Vx As Variant
    Dim Vy As Variant
    Dim dblMx(0 To 3, 0 To 3) As Double
    Dim mx As Variant

    ' ....

    pt = Bk.InsertionPoint
    r = Bk.Rotation
    Vx = ThisDrawing.Utility.PolarPoint(pt, r, 1#) 'X UnitVector
    Vy = ThisDrawing.Utility.PolarPoint(pt, r + pi½, 1#) 'Y UnitVector

    dblMx(0, 0) = Vx(0): dblMx(0, 1) = Vy(0): dblMx(0, 2) = 0: dblMx(0, 3) = pt(0)
    dblMx(1, 0) = Vx(1): dblMx(1, 1) = Vy(1): dblMx(1, 2) = 0: dblMx(1, 3) = pt(1)
    dblMx(2, 0) = Vx(2): dblMx(2, 1) = Vy(2): dblMx(2, 2) = 1: dblMx(2, 3) = pt(2)
    dblMx(3, 0) = 0: dblMx(3, 1) = 0: dblMx(3, 2) = 0: dblMx(3, 3) = 1

    'if you want to mirror about Y, i.e. from the first quadrant XY to the second quadrant -XY
    dblMx(0, 0) = -1 * dblMx(0, 0): dblMx(0, 1) = -1 * dblMx(0, 1)

    'then
    mx = dblMx
    Bk.TransformBy mx
    Bk.Update
     
    antmjr, Mar 14, 2005
    #5
  6. I need to use TransformBy as Mirror method creates new object in DWG database, and that's what I'm trying to avoid. In fact, my original object is nested in an anonymous group, also having attached XData and a reactor. If I was using Mirror, I'd need to perform 15 operations instead of that specific one.

    Anyway, thanks Antmjr for the tip on transformation matrices.

    Regards,
    Maksim Sestic
    I might be ignorant of your motives, but why not use the Mirror method?
    Dear all,

    Can anyone tell me what transformation matrix do I need to mirror a block around given 3D point (actually block's InsertionPoint)? I read everything available on TransformBy and I still can't apply that one.

    Regards,
    Maksim Sestic
     
    Maksim Sestic, Mar 20, 2005
    #6
  7. Maksim Sestic

    antmjr Guest

    About what I wrote: the general idea is right, but there are many inconsistencies, sorry, I had no time to try out. Years ago I wrote a function in autolisp with grvecs (AutoCAD11!), using a transformation matrix of that type. But I never used it in vba, where the coords are quite always expressed in WCS, hence it's different. Maybe you have already noticed a big error; UnitVectors start from the WCSOrigin (0,0,0), hence:
    Vx = ThisDrawing.Utility.PolarPoint(WCSOrigin, r, 1#) 'X UnitVector
    Vy = ThisDrawing.Utility.PolarPoint(WCSOrigin, r + pi½, 1#) 'Y UnitVector

    In general, I think you ought to translate your block to (0,0,0) first, using something like:
    a b c -X
    d e f -Y
    g h i -Z
    0 0 0 1
    where (X,Y,Z) is the insertion point of your block.
    - - -
    Then to mirror your block about the X or Y WCS axis; for instance
    a b c 0
    -d -e -f 0
    g h i 0
    0 0 0 1
    - - -
    eventually to move your block again to the original position with something like:
    a b c X
    d e f Y
    g h i Z
    0 0 0 1
     
    antmjr, Mar 21, 2005
    #7
  8. Maksim Sestic

    TomD Guest

    Thank you very much for the reply, Maksim. I didn't mean to suggest you didn't need the TransformBy, I was just totally ignorant as to why you would.

    Always nice to be enlightened. ;)
    I need to use TransformBy as Mirror method creates new object in DWG database, and that's what I'm trying to avoid. In fact, my original object is nested in an anonymous group, also having attached XData and a reactor. If I was using Mirror, I'd need to perform 15 operations instead of that specific one.

    Anyway, thanks Antmjr for the tip on transformation matrices.

    Regards,
    Maksim Sestic
    I might be ignorant of your motives, but why not use the Mirror method?
    Dear all,

    Can anyone tell me what transformation matrix do I need to mirror a block around given 3D point (actually block's InsertionPoint)? I read everything available on TransformBy and I still can't apply that one.

    Regards,
    Maksim Sestic
     
    TomD, Mar 21, 2005
    #8
  9. Actually, if I was in Autodesk's VBA implementation group, I would implement Mirror method with one more property (call it "Copy", typeof Boolean). If it's True, then standard Mirror is performed and we receive newly created object. If user passes False to it, it might perform TransformBy on original object (just like Rotate method does).

    ObjectARX implements SetToMirroring with a plane parameter. Alas, VB-ers need to do it all by themselves :)

    Regards,
    Maksim Sestic
    Thank you very much for the reply, Maksim. I didn't mean to suggest you didn't need the TransformBy, I was just totally ignorant as to why you would.

    Always nice to be enlightened. ;)
    I need to use TransformBy as Mirror method creates new object in DWG database, and that's what I'm trying to avoid. In fact, my original object is nested in an anonymous group, also having attached XData and a reactor. If I was using Mirror, I'd need to perform 15 operations instead of that specific one.

    Anyway, thanks Antmjr for the tip on transformation matrices.

    Regards,
    Maksim Sestic
    I might be ignorant of your motives, but why not use the Mirror method?
    Dear all,

    Can anyone tell me what transformation matrix do I need to mirror a block around given 3D point (actually block's InsertionPoint)? I read everything available on TransformBy and I still can't apply that one.

    Regards,
    Maksim Sestic
     
    Maksim Sestic, Mar 21, 2005
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.