123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556 |
- define(['exports', './when-8d13db60', './Check-70bec281', './Cartographic-fe4be337', './Cartesian2-85064f09', './BoundingSphere-775c5788', './Cartesian4-5af5bb24', './Transforms-b2e71640', './IntersectionTests-397d9494', './Plane-8390418f'], function (exports, when, Check, Cartographic, Cartesian2, BoundingSphere, Cartesian4, Transforms, IntersectionTests, Plane) { 'use strict';
-
- function AxisAlignedBoundingBox(minimum, maximum, center) {
-
- this.minimum = Cartographic.Cartesian3.clone(when.defaultValue(minimum, Cartographic.Cartesian3.ZERO));
-
- this.maximum = Cartographic.Cartesian3.clone(when.defaultValue(maximum, Cartographic.Cartesian3.ZERO));
-
- if (!when.defined(center)) {
- center = Cartographic.Cartesian3.midpoint(this.minimum, this.maximum, new Cartographic.Cartesian3());
- } else {
- center = Cartographic.Cartesian3.clone(center);
- }
-
- this.center = center;
- }
-
- AxisAlignedBoundingBox.fromPoints = function(positions, result) {
- if (!when.defined(result)) {
- result = new AxisAlignedBoundingBox();
- }
- if (!when.defined(positions) || positions.length === 0) {
- result.minimum = Cartographic.Cartesian3.clone(Cartographic.Cartesian3.ZERO, result.minimum);
- result.maximum = Cartographic.Cartesian3.clone(Cartographic.Cartesian3.ZERO, result.maximum);
- result.center = Cartographic.Cartesian3.clone(Cartographic.Cartesian3.ZERO, result.center);
- return result;
- }
- var minimumX = positions[0].x;
- var minimumY = positions[0].y;
- var minimumZ = positions[0].z;
- var maximumX = positions[0].x;
- var maximumY = positions[0].y;
- var maximumZ = positions[0].z;
- var length = positions.length;
- for ( var i = 1; i < length; i++) {
- var p = positions[i];
- var x = p.x;
- var y = p.y;
- var z = p.z;
- minimumX = Math.min(x, minimumX);
- maximumX = Math.max(x, maximumX);
- minimumY = Math.min(y, minimumY);
- maximumY = Math.max(y, maximumY);
- minimumZ = Math.min(z, minimumZ);
- maximumZ = Math.max(z, maximumZ);
- }
- var minimum = result.minimum;
- minimum.x = minimumX;
- minimum.y = minimumY;
- minimum.z = minimumZ;
- var maximum = result.maximum;
- maximum.x = maximumX;
- maximum.y = maximumY;
- maximum.z = maximumZ;
- result.center = Cartographic.Cartesian3.midpoint(minimum, maximum, result.center);
- return result;
- };
-
- AxisAlignedBoundingBox.clone = function(box, result) {
- if (!when.defined(box)) {
- return undefined;
- }
- if (!when.defined(result)) {
- return new AxisAlignedBoundingBox(box.minimum, box.maximum, box.center);
- }
- result.minimum = Cartographic.Cartesian3.clone(box.minimum, result.minimum);
- result.maximum = Cartographic.Cartesian3.clone(box.maximum, result.maximum);
- result.center = Cartographic.Cartesian3.clone(box.center, result.center);
- return result;
- };
-
- AxisAlignedBoundingBox.equals = function(left, right) {
- return (left === right) ||
- ((when.defined(left)) &&
- (when.defined(right)) &&
- Cartographic.Cartesian3.equals(left.center, right.center) &&
- Cartographic.Cartesian3.equals(left.minimum, right.minimum) &&
- Cartographic.Cartesian3.equals(left.maximum, right.maximum));
- };
- var intersectScratch = new Cartographic.Cartesian3();
-
- AxisAlignedBoundingBox.intersectPlane = function(box, plane) {
-
- Check.Check.defined('box', box);
- Check.Check.defined('plane', plane);
-
- intersectScratch = Cartographic.Cartesian3.subtract(box.maximum, box.minimum, intersectScratch);
- var h = Cartographic.Cartesian3.multiplyByScalar(intersectScratch, 0.5, intersectScratch);
- var normal = plane.normal;
- var e = h.x * Math.abs(normal.x) + h.y * Math.abs(normal.y) + h.z * Math.abs(normal.z);
- var s = Cartographic.Cartesian3.dot(box.center, normal) + plane.distance;
- if (s - e > 0) {
- return BoundingSphere.Intersect.INSIDE;
- }
- if (s + e < 0) {
-
- return BoundingSphere.Intersect.OUTSIDE;
- }
- return BoundingSphere.Intersect.INTERSECTING;
- };
-
- AxisAlignedBoundingBox.prototype.clone = function(result) {
- return AxisAlignedBoundingBox.clone(this, result);
- };
-
- AxisAlignedBoundingBox.prototype.intersectPlane = function(plane) {
- return AxisAlignedBoundingBox.intersectPlane(this, plane);
- };
-
- AxisAlignedBoundingBox.prototype.equals = function(right) {
- return AxisAlignedBoundingBox.equals(this, right);
- };
- var scratchCart4 = new Cartesian4.Cartesian4();
-
- function EllipsoidTangentPlane(origin, ellipsoid) {
-
- Check.Check.defined('origin', origin);
-
- ellipsoid = when.defaultValue(ellipsoid, Cartesian2.Ellipsoid.WGS84);
- origin = ellipsoid.scaleToGeodeticSurface(origin);
-
- if (!when.defined(origin)) {
- throw new Check.DeveloperError('origin must not be at the center of the ellipsoid.');
- }
-
- var eastNorthUp = Transforms.Transforms.eastNorthUpToFixedFrame(origin, ellipsoid);
- this._ellipsoid = ellipsoid;
- this._origin = origin;
- this._xAxis = Cartographic.Cartesian3.fromCartesian4(BoundingSphere.Matrix4.getColumn(eastNorthUp, 0, scratchCart4));
- this._yAxis = Cartographic.Cartesian3.fromCartesian4(BoundingSphere.Matrix4.getColumn(eastNorthUp, 1, scratchCart4));
- var normal = Cartographic.Cartesian3.fromCartesian4(BoundingSphere.Matrix4.getColumn(eastNorthUp, 2, scratchCart4));
- this._plane = Plane.Plane.fromPointNormal(origin, normal);
- }
- Object.defineProperties(EllipsoidTangentPlane.prototype, {
-
- ellipsoid : {
- get : function() {
- return this._ellipsoid;
- }
- },
-
- origin : {
- get : function() {
- return this._origin;
- }
- },
-
- plane : {
- get : function() {
- return this._plane;
- }
- },
-
- xAxis : {
- get : function() {
- return this._xAxis;
- }
- },
-
- yAxis : {
- get : function() {
- return this._yAxis;
- }
- },
-
- zAxis : {
- get : function() {
- return this._plane.normal;
- }
- }
- });
- var tmp = new AxisAlignedBoundingBox();
-
- EllipsoidTangentPlane.fromPoints = function(cartesians, ellipsoid) {
-
- Check.Check.defined('cartesians', cartesians);
-
- var box = AxisAlignedBoundingBox.fromPoints(cartesians, tmp);
- return new EllipsoidTangentPlane(box.center, ellipsoid);
- };
- var scratchProjectPointOntoPlaneRay = new IntersectionTests.Ray();
- var scratchProjectPointOntoPlaneCartesian3 = new Cartographic.Cartesian3();
-
- EllipsoidTangentPlane.prototype.projectPointOntoPlane = function(cartesian, result) {
-
- Check.Check.defined('cartesian', cartesian);
-
- var ray = scratchProjectPointOntoPlaneRay;
- ray.origin = cartesian;
- Cartographic.Cartesian3.normalize(cartesian, ray.direction);
- var intersectionPoint = IntersectionTests.IntersectionTests.rayPlane(ray, this._plane, scratchProjectPointOntoPlaneCartesian3);
- if (!when.defined(intersectionPoint)) {
- Cartographic.Cartesian3.negate(ray.direction, ray.direction);
- intersectionPoint = IntersectionTests.IntersectionTests.rayPlane(ray, this._plane, scratchProjectPointOntoPlaneCartesian3);
- }
- if (when.defined(intersectionPoint)) {
- var v = Cartographic.Cartesian3.subtract(intersectionPoint, this._origin, intersectionPoint);
- var x = Cartographic.Cartesian3.dot(this._xAxis, v);
- var y = Cartographic.Cartesian3.dot(this._yAxis, v);
- if (!when.defined(result)) {
- return new Cartesian2.Cartesian2(x, y);
- }
- result.x = x;
- result.y = y;
- return result;
- }
- return undefined;
- };
-
- EllipsoidTangentPlane.prototype.projectPointsOntoPlane = function(cartesians, result) {
-
- Check.Check.defined('cartesians', cartesians);
-
- if (!when.defined(result)) {
- result = [];
- }
- var count = 0;
- var length = cartesians.length;
- for ( var i = 0; i < length; i++) {
- var p = this.projectPointOntoPlane(cartesians[i], result[count]);
- if (when.defined(p)) {
- result[count] = p;
- count++;
- }
- }
- result.length = count;
- return result;
- };
-
- EllipsoidTangentPlane.prototype.projectPointToNearestOnPlane = function(cartesian, result) {
-
- Check.Check.defined('cartesian', cartesian);
-
- if (!when.defined(result)) {
- result = new Cartesian2.Cartesian2();
- }
- var ray = scratchProjectPointOntoPlaneRay;
- ray.origin = cartesian;
- Cartographic.Cartesian3.clone(this._plane.normal, ray.direction);
- var intersectionPoint = IntersectionTests.IntersectionTests.rayPlane(ray, this._plane, scratchProjectPointOntoPlaneCartesian3);
- if (!when.defined(intersectionPoint)) {
- Cartographic.Cartesian3.negate(ray.direction, ray.direction);
- intersectionPoint = IntersectionTests.IntersectionTests.rayPlane(ray, this._plane, scratchProjectPointOntoPlaneCartesian3);
- }
- var v = Cartographic.Cartesian3.subtract(intersectionPoint, this._origin, intersectionPoint);
- var x = Cartographic.Cartesian3.dot(this._xAxis, v);
- var y = Cartographic.Cartesian3.dot(this._yAxis, v);
- result.x = x;
- result.y = y;
- return result;
- };
-
- EllipsoidTangentPlane.prototype.projectPointsToNearestOnPlane = function(cartesians, result) {
-
- Check.Check.defined('cartesians', cartesians);
-
- if (!when.defined(result)) {
- result = [];
- }
- var length = cartesians.length;
- result.length = length;
- for (var i = 0; i < length; i++) {
- result[i] = this.projectPointToNearestOnPlane(cartesians[i], result[i]);
- }
- return result;
- };
- var projectPointsOntoEllipsoidScratch = new Cartographic.Cartesian3();
-
- EllipsoidTangentPlane.prototype.projectPointOntoEllipsoid = function(cartesian, result) {
-
- Check.Check.defined('cartesian', cartesian);
-
- if (!when.defined(result)) {
- result = new Cartographic.Cartesian3();
- }
- var ellipsoid = this._ellipsoid;
- var origin = this._origin;
- var xAxis = this._xAxis;
- var yAxis = this._yAxis;
- var tmp = projectPointsOntoEllipsoidScratch;
- Cartographic.Cartesian3.multiplyByScalar(xAxis, cartesian.x, tmp);
- result = Cartographic.Cartesian3.add(origin, tmp, result);
- Cartographic.Cartesian3.multiplyByScalar(yAxis, cartesian.y, tmp);
- Cartographic.Cartesian3.add(result, tmp, result);
- ellipsoid.scaleToGeocentricSurface(result, result);
- return result;
- };
-
- EllipsoidTangentPlane.prototype.projectPointsOntoEllipsoid = function(cartesians, result) {
-
- Check.Check.defined('cartesians', cartesians);
-
- var length = cartesians.length;
- if (!when.defined(result)) {
- result = new Array(length);
- } else {
- result.length = length;
- }
- for ( var i = 0; i < length; ++i) {
- result[i] = this.projectPointOntoEllipsoid(cartesians[i], result[i]);
- }
- return result;
- };
- exports.AxisAlignedBoundingBox = AxisAlignedBoundingBox;
- exports.EllipsoidTangentPlane = EllipsoidTangentPlane;
- });
|