# Why the result of cv::affine3d(4x4) times cv::vec3d(3 dimensions vector) is still CV::Vec3d?

**URL:** <https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996>\
**Category:** C++\
**Created:** [February 14, 2023, 9:29am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996 "2023-02-14T09:29:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BugMaker](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@BugMaker](https://forum.opencv.org/u/BugMaker)\
**Post date:** [February 14, 2023, 9:29am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/1 "2023-02-14T09:29:01Z")

</div>

```auto
void function( ..... cv::Affine3d pose,....)
{
  cv::Vec3d z_axis(0.0, 0.0, dev->len);
  cv::Vec3d plane_vec = pose * z_axis;// the result of plane_vec is [-60.5844, 48.1445, -17.4011]
}

```

In my opinion, pose is a 4x4 matrix which contains a 3x3 rotation matrix, a 3x1 translation matrix and a row containing 0001, and z\_axis is an array containing 3 numbers.  
why does this happen? it seems not obey the rule of matrix multiplication.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 14, 2023, 9:36am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/2 "2023-02-14T09:36:01Z")

</div>

what makes you think, it’s a [4x4 matrix](https://docs.opencv.org/4.x/dd/d99/classcv_1_1Affine3.html) ?

also, how do you derive that pose ?  
(admittedly, it would make a lot of sense to have a 4x4, homogeneous RT mat here, just this one does not seem like it)

---

<div class="post-metadata">

**Author:** ![BugMaker](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@BugMaker](https://forum.opencv.org/u/BugMaker)\
**Post date:** [February 14, 2023, 9:57am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/3 "2023-02-14T09:57:02Z")

</div>

Because I also get a translation matrix and rotation matrix from it, so I think it is a 4x4 matrix.  
pose comes from another function

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 14, 2023, 9:59am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/4 "2023-02-14T09:59:27Z")

</div>

well it isnt.

you’d also need a homogeneous, 4d z\_axis vec for the correct transformation, no ?

again, please show construction of the pose matrix

---

<div class="post-metadata">

**Author:** ![BugMaker](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@BugMaker](https://forum.opencv.org/u/BugMaker)\
**Post date:** [February 14, 2023, 10:07am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/5 "2023-02-14T10:07:01Z")

</div>

Sorry, i can not show any more information about pose due to my power.  
But could you tell me if pose is a 3x3 matrix, how does it contains these tow matrixs?  
I mean if pose is a 4x4 matrix, then the left upper matrix is a 3x3 rotation and behind it is a 3x1 translation vector.  
maybe pose is a 3x4 matrix?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 14, 2023, 10:15am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/6 "2023-02-14T10:15:45Z")

</div>

> [@BugMaker](#):
>
> if pose is a 3x3 matrix, how does it contains these tow matrix?

any chance, it’s a homogeneous _2d_ transformation (R/T in a single 2d plane) ?  
or 3x3 rotation only ?  
otherwise, it cant be, simply.

again, no chance to know, without more details, sorry

---

<div class="post-metadata">

**Author:** ![BugMaker](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@BugMaker](https://forum.opencv.org/u/BugMaker)\
**Post date:** [February 14, 2023, 10:20am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/7 "2023-02-14T10:20:59Z")

</div>

OK, sorry to bother you so long.  
I just print the translation, it is a 3 x1 vector [153.665, -1029.43, 36.6683]  
And, could you tell me any information do you need to fix this problem.  
the definition of pose in its class is cv::affine3d

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [February 14, 2023, 10:32am UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/8 "2023-02-14T10:32:41Z")

</div>

[OpenCV: cv::Affine3\< T \> Class Template Reference](https://docs.opencv.org/4.x/dd/d99/classcv_1_1Affine3.html)

that (default and Mat4 constructor) clearly states that it holds 4x4 data. I don’t see a reason to question that.

I don’t see where multiplication is defined on that thing. I don’t see superclasses.

however, `Vec` has operators… but docs don’t say what operation is performed by `operator*`…

the operation M v should result in another vector that is either 4-element (generally) or 3-element (affine). did you expect something other than a vector?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 14, 2023, 12:10pm UTC](https://forum.opencv.org/t/why-the-result-of-cv-affine3d-4x4-times-cv-vec3d-3-dimensions-vector-is-still-cv-vec3d/11996/9 "2023-02-14T12:10:32Z")

</div>

ok, sorry, @crackwitz is right here:

> <https://github.com/opencv/opencv/blob/4.x/modules/core/include/opencv2/core/affine.hpp#L629-L638>

(and it’s not a homogeneous transform, as i assumed)
