在3D空间中沿X轴旋转平面时,如何计算底部边缘的高度? [英] How do I calculate the height of the bottom edge when rotating a plane on the x-axis in 3d space?

查看:92
本文介绍了在3D空间中沿X轴旋转平面时,如何计算底部边缘的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iOS应用中,我正在3D空间中的X轴上进行平移。视图的锚点位于顶部中心。如果将视图旋转M_PI度,它将看起来变得平坦。我需要在屏幕底部和旋转视图底部之间保持X像素(实际上,底部边缘离地面的高度必须为X px)。如何计算M_PI的百分比?

In my iOS app, I have a view that I'm translating on the X axis in 3D space. The anchor point for the view is in the top center. If I rotate the view M_PI degrees, it will appear to go flat. I need X pixels between the bottom of the screen and the bottom edge of the rotated view (essentially, the bottom edge's height off the ground needs to be X px). How do I calculate this percentage of M_PI?

这里有一个例子。在这种情况下,视图的高度为100px,因此我需要将其旋转到M_PI的某个百分比,以使距屏幕底部边缘40px。

Here's an example. In this case the view is 100px high, and I need to rotate it some percentage of M_PI such that there's 40px from the bottom edge of the screen.

推荐答案

简单三角学。如果要在形状的底部和屏幕的底部之间放置40个像素,则形状的顶部和底部边缘之间应该包含60个像素。您知道旋转之前形状是100像素高,因此要找到角度,只需将arccos(60/100)=53.13º= .295167 * M_PI。

This is fairly simple trigonometry. If you want 40 pixels between the bottom of your shape and the bottom of the screen, then you have 60 pixels between the top and bottom edges of your shape. You know that before rotation your shape was 100 pixels tall, so to find the angle, just take arccos(60/100) = 53.13º = .295167 * M_PI.

这篇关于在3D空间中沿X轴旋转平面时,如何计算底部边缘的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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