void Init(Tuple <GeoAnchor, GeoAnchor> anchors) { // To compute the distance between two geographical co-ordinates, we first need to // convert to MapKit co-ordinates fromAnchorFloorplanPoint = anchors.Item1.Pixel; fromAnchorMKPoint = MKMapPoint.FromCoordinate(anchors.Item1.LatitudeLongitude); MKMapPoint toAnchorMKPoint = MKMapPoint.FromCoordinate(anchors.Item2.LatitudeLongitude); // So that we can use MapKit's helper function to compute distance. // this helper function takes into account the curvature of the earth. var distanceBetweenPointsMeters = (nfloat)MKGeometry.MetersBetweenMapPoints(fromAnchorMKPoint, toAnchorMKPoint); var dx = anchors.Item1.Pixel.X - anchors.Item2.Pixel.X; var dy = anchors.Item1.Pixel.Y - anchors.Item2.Pixel.Y; // Distance between two points in pixels (on the floorplan image) var distanceBetweenPointsPixels = Hypot(dx, dy); // This gives us pixels/meter PixelsPerMeter = distanceBetweenPointsPixels / distanceBetweenPointsMeters; // Get the 2nd anchor's eastward/southward distance in meters from the first anchor point. var hyp = FetchRect(fromAnchorMKPoint, toAnchorMKPoint); // Angle of diagonal to east (in geographic) nfloat angleFromEastAndHypo = NMath.Atan2(hyp.South, hyp.East); // Angle of diagonal to horizontal (in floorplan) nfloat angleFromXAndHypo = NMath.Atan2(dy, dx); // Rotation amount from the geographic anchor line segment // to the floorplan anchor line segment // This is angle between X axis and East direction. This angle shows how you floor plan exists in real world radiansRotated = angleFromXAndHypo - angleFromEastAndHypo; }
// Compute the rotation matrix from one point to another on a unit sphere. SCNMatrix4 RotationFromPoint(Vector3 start, Vector3 end) { var axis = Vector3.Cross(start, end); var angle = NMath.Atan2(axis.Length, Vector3.Dot(start, end)); return(SCNMatrix4.CreateFromAxisAngle(axis, (float)angle)); }