diff --git a/CHANGES.md b/CHANGES.md index f2547b6a7d4..42cc192c3c5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -40,6 +40,7 @@ Change Log * Fixed sandcastle Particle System example for better visual [#6132](https://github.com/AnalyticalGraphicsInc/cesium/pull/6132) * Fixed camera movement and look functions for 2D mode [#5884](https://github.com/AnalyticalGraphicsInc/cesium/issues/5884) * Fixed discrepancy between default value used and commented value for default value for halfAxes of OrientedBoundingBox. [#6147](https://github.com/AnalyticalGraphicsInc/cesium/pull/6147) +* Added `Cartographic.toCartesian` to convert from Cartographic to Cartesian3. [#6163](https://github.com/AnalyticalGraphicsInc/cesium/pull/6163) ### 1.41 - 2018-01-02 diff --git a/Source/Core/Cartographic.js b/Source/Core/Cartographic.js index a4ae56af58d..f74e8d139c4 100644 --- a/Source/Core/Cartographic.js +++ b/Source/Core/Cartographic.js @@ -146,6 +146,23 @@ define([ return result; }; + /** + * Creates a new Cartesian3 instance from a Cartographic input. The values in the inputted + * object should be in radians. + * + * @param {Cartographic} cartographic Input to be converted into a Cartesian3 output. + * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies. + * @param {Cartesian3} [result] The object onto which to store the result. + * @returns {Cartesian3} The position + */ + Cartographic.toCartesian = function(cartographic, ellipsoid, result) { + //>>includeStart('debug', pragmas.debug); + Check.defined('cartographic', cartographic); + //>>includeEnd('debug'); + + return Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height, ellipsoid, result); + }; + /** * Duplicates a Cartographic instance. * diff --git a/Specs/Core/CartographicSpec.js b/Specs/Core/CartographicSpec.js index d7d777d01b6..d312e3fc9a5 100644 --- a/Specs/Core/CartographicSpec.js +++ b/Specs/Core/CartographicSpec.js @@ -27,6 +27,16 @@ defineSuite([ expect(c.height).toEqual(3); }); + it('toCartesian conversion from Cartographic input to Cartesian3 output', function(){ + var lon = CesiumMath.toRadians(150); + var lat = CesiumMath.toRadians(-40); + var height = 100000; + var ellipsoid = Ellipsoid.WGS84; + var actual = Cartographic.toCartesian(new Cartographic(lon, lat, height)); + var expected = ellipsoid.cartographicToCartesian(new Cartographic(lon, lat, height)); + expect(actual).toEqual(expected); + }); + it('fromRadians works without a result parameter', function() { var c = Cartographic.fromRadians(Math.PI/2, Math.PI/4, 100.0); expect(c.longitude).toEqual(Math.PI/2);