<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — distance & altitude]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1226&amp;type=atom" />
	<updated>2019-06-11T20:00:58Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1226</id>
		<entry>
			<title type="html"><![CDATA[Re: distance & altitude]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5141#p5141" />
			<content type="html"><![CDATA[<p>Hello.</p><p>This method is completely wrong.<br />Thank you for reporting this.<br />This method is marked as obsolete and incorrect.</p><p>The new version of the method (the next version will contain this):<br /></p><div class="codebox"><pre><code>public static double DistanceBetweenPoints(double x1, double y1, double a1, double x2, double y2, double a2)
{
    double r = R + Math.Min(a1, a2);
    double scfY = Math.Sin(y1 * Deg2Rad);
    double sctY = Math.Sin(y2 * Deg2Rad);
    double ccfY = Math.Cos(y1 * Deg2Rad);
    double cctY = Math.Cos(y2 * Deg2Rad);
    double cX = Math.Cos((x1 - x2) * Deg2Rad);
    double sizeX1 = Math.Abs(r * Math.Acos(scfY * scfY + ccfY * ccfY * cX));
    double sizeX2 = Math.Abs(r * Math.Acos(sctY * sctY + cctY * cctY * cX));
    double dx = (sizeX1 + sizeX2) / 2.0;
    double dy = r * Math.Acos(scfY * sctY + ccfY * cctY);
    if (double.IsNaN(dx)) dx = 0;
    if (double.IsNaN(dy)) dy = 0;
    double d = Math.Sqrt(dx * dx + dy * dy);
    double hd = Math.Abs(a1 - a2);
    return Math.Sqrt(d * d + hd * hd);
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2019-06-11T20:00:58Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5141#p5141</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[distance & altitude]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5140#p5140" />
			<content type="html"><![CDATA[<p>Hi</p><p>I want to measure the exact distance between to points.</p><p>Those two points are defined by a latitude, longitude, and altitude.</p><p>OnlineMapsUtils provide two functions : one that doesn&#039;t take the altitude into account, and one that does.</p><p>However when i try to compare the result of the two method, i get roughly the same result. See the example below :</p><p><a href="https://gph.is/g/a9pOAOJ">https://gph.is/g/a9pOAOJ</a></p><div class="codebox"><pre><code> //GpsCoordinates is lat, lng, and altitude in meters
        GpsCoordinates A = new GpsCoordinates(48.332300, -70.992836, 0);
        GpsCoordinates B = new GpsCoordinates(48.332200, -70.992836, 0.2); //small difference in latitude, 200 meters difference in altitude

        double dx, dy;
        OnlineMapsUtils.DistanceBetweenPoints(A.Longitude, A.Latitude, B.Longitude, B.Latitude, out dx, out dy);

        Debug.Log(&quot;distance between A and B (no altitude taken into account) : &quot; + Math.Sqrt(dx * dx + dy * dy) * 1000 + &quot; m&quot;);

        OnlineMapsUtils.DistanceBetweenPoints(A.Longitude, A.Latitude,(float)A.Altitude, B.Longitude, B.Latitude,(float)B.Altitude, out dx, out dy);

        Debug.Log(&quot;distance between A and B (altitude should matter in the result): &quot; + Math.Sqrt(dx * dx + dy * dy) * 1000 + &quot; m&quot;);
        
        //representation of the two points on the map :

        string label = &quot;PointA&quot;;
        OnlineMapsMarker3D marker = OnlineMapsMarker3DManager.instance.Create(A.Longitude, A.Latitude, prefab);
        marker.prefab.name = label;
        marker.tags.Add(label);
        marker.altitudeType = OnlineMapsAltitudeType.relative;
        marker.altitude = (float)A.Altitude*1000;

        label = &quot;PointB&quot;;
        OnlineMapsMarker3D marker2 = OnlineMapsMarker3DManager.instance.Create(B.Longitude,B.Latitude, prefab);
        marker2.prefab.name = label;
        marker2.tags.Add(label);
        marker2.altitudeType = OnlineMapsAltitudeType.relative;
        marker2.altitude = (float)B.Altitude*1000;</code></pre></div><p>This is what i get : <br /><span class="postimg"><img src="https://i.ibb.co/r3rV9PT/distance-And-Altitude.jpg" alt="https://i.ibb.co/r3rV9PT/distance-And-Altitude.jpg" /></span></p><p>I was expecting the distance to be 200 meters and more. How can i get the exact distance between my two points ?</p>]]></content>
			<author>
				<name><![CDATA[Thibault]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=821</uri>
			</author>
			<updated>2019-06-11T19:22:06Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5140#p5140</id>
		</entry>
</feed>
