-webkit-perspective 背后的数学原理是什么?

发布于 2024-12-14 03:38:20 字数 205 浏览 7 评论 0原文

我找不到答案的“简单”问题 - -webkit-perspective 实际上在数学上做了什么? (我知道它的效果,它基本上就像一个焦距控制)例如 -webkit-perspective: 500 是什么意思?!?

我需要找到使用 -webkit-perspective 等方式移动的内容在屏幕上的位置

"Simple" question that I can't find the answer to -- What does -webkit-perspective actually do mathematically? (I know the effect it has, it basically acts like a focal-length control) e.g. what does -webkit-perspective: 500 mean?!?

I need to find the on-screen location of something that's been moved using, among other things, -webkit-perspective

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世态炎凉 2024-12-21 03:38:21

CSS 3D 变换模块工作草案给出了以下解释:

视角(<数字>)

指定透视投影矩阵。该矩阵将观察立方体映射到金字塔上,金字塔的底部距离物体无限远
观察者,其峰值代表观察者的位置。可见的
区域是由视口的四个边(即
浏览器窗口的一部分,用于在之间呈现网页
观察者的位置和距物体无穷远的点
观众)。深度作为函数的参数给出,表示
z=0 平面与观察者的距离。较低的值给出
金字塔更扁平,因此视角更明显
影响。该值以像素为单位给出,因此值为 1000 表示
适度的缩短,值为 200 给出了极端
数量。该矩阵是通过从单位矩阵开始计算的
将第 3 行第 4 列的值替换为值 -1/深度。这
深度值必须大于零,否则函数为
无效。

即使还不完全清楚,这也是一个开始。第一句话让我相信维基百科上的透视投影矩阵文章可能会有所帮助,尽管在评论中在这篇文章中,我们发现 CSS 工作组的约定与 Wikipedia 中的约定之间可能存在一些细微的差异,因此请检查一下这些约定,以免让自己头疼。

The CSS 3D Transforms Module working draft gives the following explanation:

perspective(<number>)

specifies a perspective projection matrix. This matrix maps a viewing cube onto a pyramid whose base is infinitely far away from the
viewer and whose peak represents the viewer's position. The viewable
area is the region bounded by the four edges of the viewport (the
portion of the browser window used for rendering the webpage between
the viewer's position and a point at a distance of infinity from the
viewer). The depth, given as the parameter to the function, represents
the distance of the z=0 plane from the viewer. Lower values give a
more flattened pyramid and therefore a more pronounced perspective
effect. The value is given in pixels, so a value of 1000 gives a
moderate amount of foreshortening and a value of 200 gives an extreme
amount. The matrix is computed by starting with an identity matrix and
replacing the value at row 3, column 4 with the value -1/depth. The
value for depth must be greater than zero, otherwise the function is
invalid.

This is something of a start, if not entirely clear. The first sentence leads me to believe the perspective projection matrix article on Wikipedia might be of some help, although in the comments on this post it is revealed there might be some slight differences between the CSS Working Group's conventions and those found in Wikipedia, so please check those out to save yourself a headache.

琴流音 2024-12-21 03:38:21

查看http://en.wikipedia.org/wiki/Perspective_projection#Diagram

阅读后 之前的评论并做了一些研究和测试,我很确定这是正确的。

请注意,Y 坐标也是如此。

变换后的 X = 原始 X * ( 视角 / ( 视角 - Z 平移 ) )

例如。
Div 宽 500px
视角为10000px
Z 方向变换为 -5000px

变换宽度 = 500 * ( 10000 / ( 10000 - ( -5000 ) )
变换后的宽度 = 500 * ( 10000 / 15000) = 500 * (2/3) = 333px

Check out http://en.wikipedia.org/wiki/Perspective_projection#Diagram

After reading the previous comments and doing some research and testing I'm pretty sure this is correct.

Notice that this is same for the Y coord too.

Transformed X = Original X * ( Perspective / ( Perspective - Z translation ) )

eg.
Div is 500px wide
Perspective is 10000px
Transform is -5000px in Z direction

Transformed Width = 500 * ( 10000 / ( 10000 - ( -5000 ) )
Transformed Width = 500 * ( 10000 / 15000) = 500 * (2/3) = 333px

も星光 2024-12-21 03:38:21

@Domenic 奇怪的是,描述“矩阵是通过从单位矩阵开始并用值 -1/深度替换第 3 行、第 4 列的值来计算的。”已从 CSS 3D 变换模块 中删除现在起草。也许这个描述可能存在一些不准确之处。

好吧,至于perspective()中的数字意味着什么,我认为它可以被视为想象的相机位置与计算机屏幕之间的距离。

@Domenic Oddly enough, the description "The matrix is computed by starting with an identity matrix and replacing the value at row 3, column 4 with the value -1/depth." has already been removed from the The CSS 3D Transforms Module working draft now. Perhaps there might have been some inaccuracies with this description.

Well, as to the question what does the number in perspective(<number>) means, I think it could be seen as the distance between the position of the imagined camera and your computer screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文