Scaling 3D models, finding the origin

2019-08-24 03:39发布

To get a better idea of how matrix transformations work cause I'm having a fairly hard time seeing what actually happens, I decided to write some scripts that will take a 3D model and then do some translations, rotations, and scaling, since looking at what actually happens when I play around with different values may be helpful.

I've already written the scripts to parse a 3D model, so now I just need to write the transformation functions.

I am using the Euclid module, which was amongst several suggestions for working with matrices (though this question is not really python-specific so I left out that tag)

So far I've been able to successfully translate a model based on the x,y,z values that I provide.

Now I'm working on the scaling function, and have also managed to scale the model by whatever factor, but I'm having a hard time getting it to scale "on the spot" since the model isn't centered at the origin.

How can I build a transform matrix that will take into account the center of some arbitrary model?

1条回答
The star\"
2楼-- · 2019-08-24 04:21

You may scale "around" a point P by the following transformation:

translate(scale(translate(model, -P)), P)

i.e. for a vertex X you have

X' = P + s * (X-P) = s*X + (P-s*P)
查看更多
登录 后发表回答