Set camera looking at point without specifying heading or pitch

08-06-2015 09:12 AM
New Contributor III

Is there a way to set the camera looking at a specific point in the scene without specifying a heading or pitch explicitly? I found a how to calculate pitch and heading using the haversine formula, but I was wondering if ArcGIS could do this for me. I want something similar to this:

Esri.ArcGISRuntime.Geometry.MapPoint mapPoint1 = new Esri.ArcGISRuntime.Geometry.MapPoint(cameraX, cameraY, cameraAlt);

Esri.ArcGISRuntime.Geometry.MapPoint mapPoint2 = new Esri.ArcGISRuntime.Geometry.MapPoint(targetX, targetY, targetAlt);

Esri.ArcGISRuntime.Controls.Camera camera = new Camera(mapPoint1,0,0);


//Esri.ArcGISRuntime.Controls.Camera camera = new Camera(mapPoint1,calculatedHeading,calculatedPitch);

Viewpoint vp = new Viewpoint(camera, mapPoint2); //camera looks at mapPoint2



0 Kudos
2 Replies
Esri Frequent Contributor

A camera is defined by it's location, heading and pitch, so you will have to specify some value.

Is the intent to have them to be 0, or to be the same as the current values? If you want the current heading/pitch, you can use the RotateAround method to create a suitable camera:

MapPoint poi = new MapPoint(12, 56, SpatialReferences.Wgs84);

var currentCam = sceneView.Camera;

var newCamera = new Camera(poi.Y, poi.X, 1000, 0, 0); //Look straight down

newCamera = newCamera.RotateAround(poi, -currentCam.Heading, currentCam.Pitch);


0 Kudos
New Contributor III


All I want is to specify the camera's position , and a second point, and have the camera look straight at that second point. I curently just calculate a pitch and a heading using the haversine formula

Esri.ArcGISRuntime.Geometry.MapPoint mapPoint1 = new Esri.ArcGISRuntime.Geometry.MapPoint(cameraLon, cameraLat, cameraAlt);

Esri.ArcGISRuntime.Geometry.MapPoint mapPoint2 = new Esri.ArcGISRuntime.Geometry.MapPoint(targetLon, targetLat, targetAlt);

//get distance

double d = distance(cameraLat, cameraLon, targetLat, targetLon, 'K') * 1000;

double t1 = deg2rad(cameraLat);

double t2 = deg2rad(targetLat);

double dt = deg2rad(targetLat - cameraLat);

double dl = deg2rad(targetLon - cameraLon);

double alt = cameraAlt - targetAlt;

double pitch = 90 - rad2deg(Math.Atan2(alt, d));

//get heading

double y = Math.Sin(dl - dt) * Math.Cos(t2);

double x = Math.Cos(t1) * Math.Sin(t2) -

  Math.Sin(t1) * Math.Cos(t2) * Math.Cos(dl - dt);

double heading = rad2deg(Math.Atan2(y, x)) + 45;

Esri.ArcGISRuntime.Controls.Camera camera = new Camera(mapPoint1, heading, pitch);

Viewpoint vp = new Viewpoint(camera, mapPoint2);


I would like to not have to calculate the heading and pitch, since this is not always accurate.

0 Kudos