Scaling 3D models, finding the origin

孤者浪人 提交于 2019-12-13 07:10:57

问题


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:


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)


来源:https://stackoverflow.com/questions/6684851/scaling-3d-models-finding-the-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!