How to draw and rotate an arrow on orientation in 3D space?

I want to draw an image like the following in a specific orientation.

enter image description here

Suppose the device lies flat on the table, the image above shows how the arrow should be drawn. The angle between the device and the table is called alpha , in which case it is zero. The arrow points directly to a predetermined location point. If you rotate the device on a table, the arrow will point in the direction of the target just like a compass.

I updated the position of the image with the following code in 2D space:

 // Create the image for the compass let arrowImageView: UIImageView = UIImageView(frame: CGRectMake(100, 200, 100, 100)) arrowImageView.image = UIImage(named: "arrow.png") self.view.addSubview(arrowImageView) arrowImageView.center = self.view.center func locationManager(manager: CLLocationManager!, didUpdateHeading newHeading: CLHeading!) { var direction: Float = Float(newHeading.magneticHeading) if direction > 180 { direction = 360 - direction } else { direction = 0 - direction } // Rotate the arrow image if let arrowImageView = self.arrowImageView { UIView.animateWithDuration(3.0, animations: { () -> Void in arrowImageView.transform = CGAffineTransformMakeRotation(CGFloat(self.degreesToRadians(direction) + self.angle)) }) } let currentLocation: CLLocation = manager.location } 

However, if the device rises from the table, the alpha value increases ( alpha > 0 ). The arrow image should still indicate the target location, but should be facing in perspective, taking into account the angle of the alpha. This is how it looks from the outside.

enter image description here

The only thing that changes in 3D space is the angle alpha . All other angles remain constant.

How to draw and rotate an arrow image in orientation (given alpha angle) in 3D space?

+2
ios objective-c swift core-animation catransform3d
source share

No one has answered this question yet.

See similar questions:

7
Determine the orientation of the device and its resulting angle in one dimension?

or similar:

1665
How can I make UITextField move up when there is a keyboard - when editing starts?
1276
How to disable ARC for a single file in a project?
1172
How can I turn off UITableView selection?
1141
How can I develop for iPhone using a Windows development machine?
346
How to draw a shadow under UIView?
2
Pointing in the right direction in SceneKit
2
X and Z values ​​influence Euler Angles Y values ​​- how do I reset them to get a “true” y value?
2
IPhone Orientation - How Do I Know Which Way Up?
0
C target UIImageView rotation with animation not working well
0
Swift - draw an arrow over qr code

All Articles