Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cartographic to cartesian3 method #6163

Merged
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions Source/Core/Cartographic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions Specs/Core/CartographicSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down