Calculating an AABB for a transformed sphere

后端 未结 4 489
夕颜
夕颜 2021-02-05 16:37

I have a sphere represented in object space by a center point and a radius. The sphere is transformed into world space with a transformation matrix that may include scales, rota

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 17:20

    @comingstorm's answer is great but can be simplified a lot. If M is the sphere's transformation matrix, indexed from 1, then

    x = M[1,4] +/- sqrt(M[1,1]^2 + M[1,2]^2 + M[1,3]^2)
    y = M[2,4] +/- sqrt(M[2,1]^2 + M[2,2]^2 + M[2,3]^2)
    z = M[3,4] +/- sqrt(M[3,1]^2 + M[3,2]^2 + M[3,3]^2)
    

    (This assumes the sphere had radius 1 and its center at the origin before it was transformed.)

    I wrote a blog post with the proof here, which is much too long for a reasonable Stack Overflow answer.

提交回复
热议问题