diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index d1e033eafb5c..a35448307ba1 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -262,9 +262,9 @@ define([ geometry = PolygonPipeline.scaleToGeodeticHeight(geometry, height, ellipsoid); var center = boundingSphere.center; - var mag = center.magnitude(); - ellipsoid.geodeticSurfaceNormal(center, center); - Cartesian3.multiplyByScalar(center, mag + height, center); + ellipsoid.geodeticSurfaceNormal(center, scratchNormal); + Cartesian3.multiplyByScalar(scratchNormal, height, scratchNormal); + Cartesian3.add(center, scratchNormal, center); var attributes = new GeometryAttributes(); diff --git a/Specs/Core/PolygonGeometrySpec.js b/Specs/Core/PolygonGeometrySpec.js index 1700875bf85d..fa5ce8e08965 100644 --- a/Specs/Core/PolygonGeometrySpec.js +++ b/Specs/Core/PolygonGeometrySpec.js @@ -1,17 +1,21 @@ /*global defineSuite*/ defineSuite([ 'Core/PolygonGeometry', + 'Core/BoundingSphere', 'Core/Cartesian3', 'Core/Cartographic', 'Core/Ellipsoid', 'Core/Math', + 'Core/Shapes', 'Core/VertexFormat' ], function( PolygonGeometry, + BoundingSphere, Cartesian3, Cartographic, Ellipsoid, CesiumMath, + Shapes, VertexFormat) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -194,4 +198,18 @@ defineSuite([ expect(p.indices.length).toEqual(3 * 10); }); + it('computes correct bounding sphere at height 0', function() { + var ellipsoid = Ellipsoid.WGS84; + var center = new Cartographic(0.2930215893394521, 0.818292397338644, 1880.6159971414636); + var positions = Shapes.computeCircleBoundary(ellipsoid, ellipsoid.cartographicToCartesian(center), 10000); + + var p = PolygonGeometry.fromPositions({ + vertexFormat : VertexFormat.ALL, + positions : positions, + granularity : CesiumMath.PI_OVER_THREE + }); + + expect(p.boundingSphere).toEqual(BoundingSphere.fromPoints(positions)); + }); + }, 'WebGL');