Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
674 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...