Author Topic: Helmert Transformation  (Read 574 times)

0 Members and 1 Guest are viewing this topic.

Bernd

  • Mosquito
  • Posts: 13
Helmert Transformation
« on: March 19, 2018, 05:51:45 AM »
Hi there,

I want to apply a transformation to a drawing (from German Gauß-Krüger to UTM). Parameters are:
Scale factor 0.9996
Rotation 0.000006
Displacement 28999941.883,-1729.851
How do I have to construct the matrix to transform the drawing's elements?
I tried:
Code - C#: [Select]
  1. /* Point3d centerOld: Origin of translation vector
  2.    Point3d centerNew: Target of translation vector
  3.    double rotation: in radians
  4.    double scaleFactor */
  5. var matrix = Matrix3d.Displacement(centerNew - centerOld);
  6. matrix *= Matrix3d.Scaling(scaleFactor, centerNew);
  7. matrix *= Matrix3d.Rotation(rotation, new Vector3d(0, 0, 1), centerNew);
  8. // and later on...
  9. entity.TransformBy(matrix);
Apparently the transformation is not correct (around 13 kilometers off in X, pretty close in Y).  :straight:
Any ideas?

MickD

  • Gator
  • Posts: 3129
  • I don't need a job, I need Money!!
Re: Helmert Transformation
« Reply #1 on: March 19, 2018, 07:14:48 AM »
could it be that rotation could be in radians?
Also, the order of each transformation is very important when multiplying matrices.
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

Bernd

  • Mosquito
  • Posts: 13
Re: Helmert Transformation
« Reply #2 on: March 19, 2018, 08:19:15 AM »
could it be that rotation could be in radians?
Rotation is supplied in radians.
Also, the order of each transformation is very important when multiplying matrices.
I thought so, but I'm not sure in which order to apply the parameters. When I do three separate transformations (entity.TransformBy(Matrix3d.Scaling(...)), then TransformBy.(Matrix3d.Rotation(...)), ...) everything's fine, but I would like to avoid that.

MickD

  • Gator
  • Posts: 3129
  • I don't need a job, I need Money!!
Re: Helmert Transformation
« Reply #3 on: March 19, 2018, 04:06:54 PM »

I thought so, but I'm not sure in which order to apply the parameters. When I do three separate transformations (entity.TransformBy(Matrix3d.Scaling(...)), then TransformBy.(Matrix3d.Rotation(...)), ...) everything's fine, but I would like to avoid that.

That's what I thought because when you multiply say a displacement by a scalar, all the displacement numbers are multiplied by that scalar!

I'd try in this order: Scalar/Rotation/Displacement

If you have to separate them then I think you would only need to do the Scalar by itself first.
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

MickD

  • Gator
  • Posts: 3129
  • I don't need a job, I need Money!!
Re: Helmert Transformation
« Reply #4 on: March 19, 2018, 04:27:41 PM »

I thought so, but I'm not sure in which order to apply the parameters. When I do three separate transformations ...  everything's fine, but I would like to avoid that.

Just rethinking your comment here.
If it works I can't see a problem with it and with some comments about the order it will be easier to maintain. While it might _seem_ more technically elegant, I'd doubt the clock cycles saved would make any real difference in the end :)
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

Bernd

  • Mosquito
  • Posts: 13
Re: Helmert Transformation
« Reply #5 on: March 19, 2018, 05:04:32 PM »
While it might _seem_ more technically elegant, I'd doubt the clock cycles saved would make any real difference in the end :)
You're certainly right about that. Nonetheless I would like to understand what I [would] have to do to apply the transformation in one step (I know I can be annoying at times  :whistling: ).

MickD

  • Gator
  • Posts: 3129
  • I don't need a job, I need Money!!
Re: Helmert Transformation
« Reply #6 on: March 19, 2018, 05:14:18 PM »
(I know I can be annoying at times  :whistling: ).

Nah! all good :)

The trick is to think what each xform is doing and what the resulting numbers look like. For instance, scaling the entity at centerOld (current center?) it will slightly shrink the ent on the spot, you can then rotate it using this same centerOld and rotate it on the spot so I think the numbers will be fine. You can now displace it along the vector to centerNew which again only translates (scales) the numbers of each 3d axis.

All numbers for each axis in a matrix are really scalers applied to the unit vector of each axis ;)
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

Bernd

  • Mosquito
  • Posts: 13
Re: Helmert Transformation
« Reply #7 on: March 19, 2018, 05:24:30 PM »
All numbers for each axis in a matrix are really scalers applied to the unit vector of each axis ;)
Ooookay - I see  :woow:
I think I tried the combination Scaling * Rotation * Displacement before, but I'll try again tomorrow - thanks for your patience (not kidding).

MickD

  • Gator
  • Posts: 3129
  • I don't need a job, I need Money!!
Re: Helmert Transformation
« Reply #8 on: March 19, 2018, 05:29:41 PM »
All numbers for each axis in a matrix are really scalers applied to the unit vector of each axis ;)
Ooookay - I see  :woow:
I think I tried the combination Scaling * Rotation * Displacement before, but I'll try again tomorrow - thanks for your patience (not kidding).

Just remember to use the correct centre! (i.e. the current 'old' one) :)
cheers.
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

WILL HATCH

  • Bull Frog
  • Posts: 448
Re: Helmert Transformation
« Reply #9 on: March 20, 2018, 01:37:41 PM »
To understand whats really going on check out this link that talks about the properties of matrix multiplication and consider especially the non commutative property, A*B != B*A, and the associative property, (A*B)*C = A*(B*C).

Now consider you are looking to scale, then rotate, then translate a point P with matrices S, R, and T

running this as 3 separate operations is equivalent to ((P*S)*R)*T, thus it's the same to pre calculate the combined matrix of S*R*T and then multiply P by that.

MickD

  • Gator
  • Posts: 3129
  • I don't need a job, I need Money!!
Re: Helmert Transformation
« Reply #10 on: March 20, 2018, 04:15:29 PM »
Great link Will!
Here's some more info in a good video series explaining things in a visual manner as he goes through the material to supplement the link Will posted - http://www.theswamp.org/index.php?topic=54028.msg586642#new
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

WILL HATCH

  • Bull Frog
  • Posts: 448
Re: Helmert Transformation
« Reply #11 on: March 21, 2018, 08:18:35 PM »
Thanks Mick! That video series will be able to reach visual learners much better than my first google result...

Bernd

  • Mosquito
  • Posts: 13
Re: Helmert Transformation
« Reply #12 on: March 22, 2018, 03:12:38 AM »
Mick and Will,
thanks for those links, certainly going to check them out as I surely need some background on this topic...