1

I have a 4x4 projection matrix

(SCNMatrix4) 
   s = (m11 = 1.83226573, 
   m12 = 0, 
   m13 = 0, 
   m14 = 0,
   m21 = 0,
   m22 = 2.44078445,
   m23 = 0,
   m24 = 0,
   m31 = -0.00576340035, 
   m32 = -0.0016724075, 
   m33 = -1.00019991, 
   m34 = -1, 
   m41 = 0, 
   m42 = 0, 
   m43 = -0.20002, 
   m44 = 0)

I would like to get the focal point and the focal length out of this matrix.

Patrick
  • 5,526
  • 14
  • 64
  • 101
andre
  • 61
  • 2
  • 7

1 Answers1

5

From slides 4 and 5 on this GDC presentation:

enter image description here

The focal length is merely the first element in the matrix (m11).

The focal point, however, cannot be extracted from this matrix alone - you need the camera direction D and position P. Once you have them, simply do P + D * m11 to obtain the focal point.

meowgoesthedog
  • 14,670
  • 4
  • 27
  • 40
  • The position of the Camera is a 3D Point, and the focal point is a 2D point.I'm confused about the position of the camera – andre Sep 06 '17 at 20:15
  • @andre why do you think that the focal point is 2D? It is a 3D point too. – meowgoesthedog Sep 06 '17 at 20:21
  • 3
    Revive of an old post, but this got me : what this doesn't say is that this 1 in the numerator for e is supposed to be half the width of the viewport. If you're doing OpenGL, this works because the viewport is [-1, 1] x [-1, 1] so half the width is indeed 1, but if you're trying to deduce the focal length for a real-world camera, the formula is indeed `m11 = 1 / tan(FOV / 2)`, but `FOV = 2 * arctan(sensor_half_width / focal_length)`, so in the end `focal_length = m11 * sensor_half_width`. Be careful that the sensor width and the focal length have the same units. – Matrefeytontias Jun 13 '19 at 17:13
  • @Matrefeytontias Also reviving this post; in OpenGL both width and heigh of the view are in `[-1;1]`. How is it possible since this means that the captor is a square of side `2`, which is obviously not always the case ? (e.g. `1920x1080`, or it would mean different focal lengths for `X` and `Y`) – rafoo Jul 21 '22 at 15:44
  • OpenGL uses what's called NDC, or Normalized Device Coordinates. OpenGL abstracts away the actual dimensions of your viewport and makes them [-1;1] uniformly across all devices. This is why we bake the ratio of the actual viewport dimensions in the matrix like explained. – Matrefeytontias Jul 29 '22 at 11:50
  • This is wrong. See [my answer](https://stackoverflow.com/a/74876243/1186624) on other question. – relent95 Dec 21 '22 at 12:52