Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
632 views
in Technique[技术] by (71.8m points)

ios - How to get scene height in meters (swift)?

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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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+?at2, 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...