缩放 3D 模型,找到原点 [英] Scaling 3D models, finding the origin

查看:40
本文介绍了缩放 3D 模型,找到原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了更好地了解矩阵变换的工作原理,因为我很难看到实际发生的情况,我决定编写一些脚本,这些脚本将采用 3D 模型,然后进行一些平移、旋转和缩放,因为看看当我玩弄不同的值时实际发生的事情可能会有所帮助.

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.

我已经编写了解析 3D 模型的脚本,所以现在我只需要编写转换函数.

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

我正在使用 Euclid 模块,这是处理矩阵的几个建议之一(尽管这个问题并不是真正针对 Python 的,所以我省略了那个标签)

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)

到目前为止,我已经能够根据我提供的 x、y、z 值成功转换模型.

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?

推荐答案

您可以通过以下转换围绕"一个点 P 缩放:

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

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

即对于顶点 X 你有

X' = P + s * (X-P) = s*X + (P-s*P)

这篇关于缩放 3D 模型,找到原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆