Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objects falling towards earth regardless of device orientation

I have seen two ways to describe falling objects behaviour for different device orientation using CoreMotion framework. I have tried both version in code and they both seem to behave as what I expect, i.e. falling toward earth regardless of device orientation.

I'm just curious why both version behave the same, even though for the first version, the acceleration in x and y direction, i.e. dx and dy, are switched at landscape orientation?

1)

if var dx = data?.acceleration.x, var dy = data?.acceleration.y {
                            switch UIDevice.currentDevice().orientation {
                            case .Portrait:
                                dy = -dy
                            case .PortraitUpsideDown:
                                break
                            case .LandscapeRight:
                                swap(&dx, &dy)
                            case .LandscapeLeft:
                                swap(&dx, &dy)
                                dy = -dy 
                            default:
                                dx = 0
                                dy = 0
                            }
                            gravity.gravityDirection = CGVector(dx: dx, dy: dy)
                        }

2)

if var dx = data?.acceleration.x, var dy = data?.acceleration.y {
                                switch UIDevice.currentDevice().orientation {
                                case .Portrait:
                                    dy = -dy
                                case .PortraitUpsideDown:
                                    break
                                case .LandscapeRight:
                                    break
                                case .LandscapeLeft:
                                    break
                                default:
                                    dx = 0
                                    dy = 0
                                }
                                gravity.gravityDirection = CGVector(dx: dx, dy: dy)
                            }
like image 687
Thor Avatar asked Sep 21 '16 04:09

Thor


People also ask

What is the motion of objects that are falling toward Earth?

As learned in an earlier unit, free fall is a special type of motion in which the only force acting upon an object is gravity. Objects that are said to be undergoing free fall, are not encountering a significant force of air resistance; they are falling under the sole influence of gravity.

Why do all objects regardless of mass experience the same falling acceleration?

Heavier things have a greater gravitational force AND heavier things have a lower acceleration. It turns out that these two effects exactly cancel to make falling objects have the same acceleration regardless of mass.

Why do objects freely fall towards the Earth?

Earth's gravitational force (force of gravity) pulls all objects towards the centre of the earth.

What is the acceleration of an object falling freely towards Earth?

Acceleration of freely falling body is the acceleration produced when a body falls under the influence of gravitational force of the earth alone. It is denoted by g and its value on the surface of the earth is 9.8 ms−2.


1 Answers

I guess you are using the simulator, so gravity is always orthogonal to the bottom.

The behaviour should differ on a real device imo., as you will always tilt the device at least slightly.

like image 155
shallowThought Avatar answered Oct 27 '22 03:10

shallowThought