且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获得以米为单位的场景高度(快速)?

更新时间:2023-02-02 10:43:18

到一米大约135点.

在9.8m/s的重力作用下从静止中坠落的PhysicsBody在1.00806862953687s(1.01s)中移动了660点,速度为1342.8162841796875m/s(1342.82).

将数学计算到小数点后两位,我们可以使用行进距离和速度方程来通过2种不同的计算来计算每米的点数:

使用v = u + at(u = 0,a = 9.8,t = 1.01s),我们可以计算出1.01s之后,v为1.01 * 9.8 = 9.90m/s.物理体的速度为1342.85,因此9.90m/s = 1342.82点/s,所以1m = 135.6点.

或者,使用s = ut + 1/2at²来计算时间t之后的行进距离,我们得出s = 0.5x9.8x1.01 = 4.95m.因此,4.95m = 660点; 1m = 133.3点.

如果完全精确地进行数学运算,您将获得137点的数字.

使用大约2秒钟后的计时,加速度公式得出的数字为133.4点/m,距离公式得出的数字为133.7点/m

奇怪的是,SKPhysicsBody类引用将速度属性描述为以米/秒为单位,但绝对以每秒点数为单位.

So I have my height as self.frame.height which returns 736 as expected for an iPhone 6s. How do I convert this value into meters to be consistent with the physicsWorld unit system??

It's about 135 points to a meter.

A physicsBody left to fall from stationary under gravity of 9.8m/s travelled 660 points in 1.00806862953687s (1.01s), with a velocity of 1342.8162841796875m/s (1342.82).

Doing the maths to 2 decimal places, we can use both the equations of distance travelled and speed to calculate the number of points per meter through 2 different calculations:

Using v=u+at (u=0, a=9.8, t=1.01s), we can calculate that after 1.01s, v is 1.01 * 9.8 = 9.90m/s. The physicsbody's velocity is 1342.85, Therefore 9.90m/s = 1342.82 points/s so 1m = 135.6 points.

Or, using s=ut+½at², to calculate the distance travelled after time t, we get s = 0.5x9.8x1.01 = 4.95m. Therefore 4.95m = 660point; 1m = 133.3 points.

If you do the maths with the full precision, you get a figure of 137 points.

Using the timings after approx 2 seconds gives a figure of 133.4 points/m from the acceleration formula and 133.7points/m from the distance formula

What is odd is that the SKPhysicsBody class reference described the velocity property as being in meters/second, but it definitely appears to be in points per second.