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

Ellipsoid Tangent Plane #1150

Merged
merged 1 commit into from
Sep 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (defined(p) && defined(p.primitive)) {
* Added `Scene.sunBloom` to enable/disable the bloom filter on the sun. The bloom filter should be disabled for better frame rates on mobile devices.
* Fix geometries not closing completely. [#1093](https://github.com/AnalyticalGraphicsInc/cesium/issues/1093)
* Improved graphics performance. For example, an Everest terrain view went from 135-140 to over 150 frames per second.
* Fix `EllipsoidTangentPlane.projectPointOntoPlane` for tangent planes on an ellipsoid other than the unit sphere.

### b20 - 2013-09-03

Expand Down
7 changes: 5 additions & 2 deletions Source/Core/EllipsoidTangentPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ define([
this._yAxis = Cartesian3.fromCartesian4(eastNorthUp.getColumn(1));

var normal = Cartesian3.fromCartesian4(eastNorthUp.getColumn(2));
var distance = -Cartesian3.dot(origin, origin); //The shortest distance from the origin to the plane.
this._plane = new Plane(normal, distance);
this._plane = Plane.fromPointNormal(origin, normal);
};

var tmp = new AxisAlignedBoundingBox();
Expand Down Expand Up @@ -119,6 +118,10 @@ define([
Cartesian3.normalize(cartesian, ray.direction);

var intersectionPoint = IntersectionTests.rayPlane(ray, this._plane, projectPointOntoPlaneCartesian3);
if (!defined(intersectionPoint)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it is obvious, but you'll have to explain this to me. How does switching the ray's direction help?

Cartesian3.negate(ray.direction, ray.direction);
intersectionPoint = IntersectionTests.rayPlane(ray, this._plane, projectPointOntoPlaneCartesian3);
}

if (defined(intersectionPoint)) {
var v = intersectionPoint.subtract(this._origin, intersectionPoint);
Expand Down
26 changes: 24 additions & 2 deletions Specs/Core/EllipsoidTangentPlaneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ defineSuite([
'Core/EllipsoidTangentPlane',
'Core/Ellipsoid',
'Core/Cartesian2',
'Core/Cartesian3'
'Core/Cartesian3',
'Core/Cartographic'
], function(
EllipsoidTangentPlane,
Ellipsoid,
Cartesian2,
Cartesian3) {
Cartesian3,
Cartographic) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/

Expand Down Expand Up @@ -167,4 +169,24 @@ defineSuite([
return tangentPlane.projectPointsOntoEllipsoid(undefined);
}).toThrow();
});

it('projectPointsOntoEllipsoid works with an arbitrary ellipsoid using fromPoints', function () {
var ellipsoid = Ellipsoid.WGS84;

var points = ellipsoid.cartographicArrayToCartesianArray([
Cartographic.fromDegrees(-72.0, 40.0),
Cartographic.fromDegrees(-68.0, 35.0),
Cartographic.fromDegrees(-75.0, 30.0),
Cartographic.fromDegrees(-70.0, 30.0),
Cartographic.fromDegrees(-68.0, 40.0)
]);

var tangentPlane = EllipsoidTangentPlane.fromPoints(points, ellipsoid);
var points2D = tangentPlane.projectPointsOntoPlane(points);
var positionsBack = tangentPlane.projectPointsOntoEllipsoid(points2D);

expect(positionsBack[0].x).toBeCloseTo(points[0].x);
expect(positionsBack[0].y).toBeCloseTo(points[0].y);
expect(positionsBack[0].z).toBeCloseTo(points[0].z);
});
});