Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | 1x 5045x 5044x 5044x 5044x 1x 5043x 5043x 5043x 5043x 5043x 5043x 5043x 1x 1389x 4284x 5331x 4727x 4727x 4281x 1x 1x 366x 365x 365x 1x 1x 1x 1770x 1769x 1769x 1769x 1769x 1769x 168x 168x 1769x 1766x 1766x 1766x 1766x 377x 1389x 1389x 1389x 3x 1x 249x 248x 90x 248x 248x 248x 756x 756x 754x 754x 248x 248x 1x 21418x 21417x 10x 21417x 21417x 21417x 21417x 21417x 13279x 13279x 21417x 21417x 21417x 21417x 21417x 21417x 1x 3x 2x 1x 2x 2x 2x 6x 2x 1x 1x 23x 23x 10x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 1x 4x 3x 3x 2x 1x 3x 9x 3x | import AxisAlignedBoundingBox from "./AxisAlignedBoundingBox.js";
import Cartesian2 from "./Cartesian2.js";
import Cartesian3 from "./Cartesian3.js";
import Cartesian4 from "./Cartesian4.js";
import Check from "./Check.js";
import defined from "./defined.js";
import DeveloperError from "./DeveloperError.js";
import Ellipsoid from "./Ellipsoid.js";
import IntersectionTests from "./IntersectionTests.js";
import Matrix4 from "./Matrix4.js";
import Plane from "./Plane.js";
import Ray from "./Ray.js";
import Transforms from "./Transforms.js";
const scratchCart4 = new Cartesian4();
/**
* A plane tangent to the provided ellipsoid at the provided origin.
* If origin is not on the surface of the ellipsoid, it's surface projection will be used.
* If origin is at the center of the ellipsoid, an exception will be thrown.
* @alias EllipsoidTangentPlane
* @constructor
*
* @param {Cartesian3} origin The point on the surface of the ellipsoid where the tangent plane touches.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid to use.
*
* @exception {DeveloperError} origin must not be at the center of the ellipsoid.
*/
function EllipsoidTangentPlane(origin, ellipsoid) {
//>>includeStart('debug', pragmas.debug);
Check.defined("origin", origin);
//>>includeEnd('debug');
ellipsoid = ellipsoid ?? Ellipsoid.default;
origin = ellipsoid.scaleToGeodeticSurface(origin);
//>>includeStart('debug', pragmas.debug);
if (!defined(origin)) {
throw new DeveloperError(
"origin must not be at the center of the ellipsoid.",
);
}
//>>includeEnd('debug');
const eastNorthUp = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid);
this._ellipsoid = ellipsoid;
this._origin = origin;
this._xAxis = Cartesian3.fromCartesian4(
Matrix4.getColumn(eastNorthUp, 0, scratchCart4),
);
this._yAxis = Cartesian3.fromCartesian4(
Matrix4.getColumn(eastNorthUp, 1, scratchCart4),
);
const normal = Cartesian3.fromCartesian4(
Matrix4.getColumn(eastNorthUp, 2, scratchCart4),
);
this._plane = Plane.fromPointNormal(origin, normal);
}
Object.defineProperties(EllipsoidTangentPlane.prototype, {
/**
* Gets the ellipsoid.
* @memberof EllipsoidTangentPlane.prototype
* @type {Ellipsoid}
*/
ellipsoid: {
get: function () {
return this._ellipsoid;
},
},
/**
* Gets the origin.
* @memberof EllipsoidTangentPlane.prototype
* @type {Cartesian3}
*/
origin: {
get: function () {
return this._origin;
},
},
/**
* Gets the plane which is tangent to the ellipsoid.
* @memberof EllipsoidTangentPlane.prototype
* @readonly
* @type {Plane}
*/
plane: {
get: function () {
return this._plane;
},
},
/**
* Gets the local X-axis (east) of the tangent plane.
* @memberof EllipsoidTangentPlane.prototype
* @readonly
* @type {Cartesian3}
*/
xAxis: {
get: function () {
return this._xAxis;
},
},
/**
* Gets the local Y-axis (north) of the tangent plane.
* @memberof EllipsoidTangentPlane.prototype
* @readonly
* @type {Cartesian3}
*/
yAxis: {
get: function () {
return this._yAxis;
},
},
/**
* Gets the local Z-axis (up) of the tangent plane.
* @memberof EllipsoidTangentPlane.prototype
* @readonly
* @type {Cartesian3}
*/
zAxis: {
get: function () {
return this._plane.normal;
},
},
});
const tmp = new AxisAlignedBoundingBox();
/**
* Creates a new instance from the provided ellipsoid and the center
* point of the provided Cartesians.
*
* @param {Cartesian3[]} cartesians The list of positions surrounding the center point.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid to use.
* @returns {EllipsoidTangentPlane} The new instance of EllipsoidTangentPlane.
*/
EllipsoidTangentPlane.fromPoints = function (cartesians, ellipsoid) {
//>>includeStart('debug', pragmas.debug);
Check.defined("cartesians", cartesians);
//>>includeEnd('debug');
const box = AxisAlignedBoundingBox.fromPoints(cartesians, tmp);
return new EllipsoidTangentPlane(box.center, ellipsoid);
};
const scratchProjectPointOntoPlaneRay = new Ray();
const scratchProjectPointOntoPlaneCartesian3 = new Cartesian3();
/**
* Computes the projection of the provided 3D position onto the 2D plane, radially outward from the {@link EllipsoidTangentPlane.ellipsoid} coordinate system origin.
*
* @param {Cartesian3} cartesian The point to project.
* @param {Cartesian2} [result] The object onto which to store the result.
* @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided. Undefined if there is no intersection point
*/
EllipsoidTangentPlane.prototype.projectPointOntoPlane = function (
cartesian,
result,
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("cartesian", cartesian);
//>>includeEnd('debug');
const ray = scratchProjectPointOntoPlaneRay;
ray.origin = cartesian;
Cartesian3.normalize(cartesian, ray.direction);
let intersectionPoint = IntersectionTests.rayPlane(
ray,
this._plane,
scratchProjectPointOntoPlaneCartesian3,
);
if (!defined(intersectionPoint)) {
Cartesian3.negate(ray.direction, ray.direction);
intersectionPoint = IntersectionTests.rayPlane(
ray,
this._plane,
scratchProjectPointOntoPlaneCartesian3,
);
}
if (defined(intersectionPoint)) {
const v = Cartesian3.subtract(
intersectionPoint,
this._origin,
intersectionPoint,
);
const x = Cartesian3.dot(this._xAxis, v);
const y = Cartesian3.dot(this._yAxis, v);
if (!defined(result)) {
return new Cartesian2(x, y);
}
result.x = x;
result.y = y;
return result;
}
return undefined;
};
/**
* Computes the projection of the provided 3D positions onto the 2D plane (where possible), radially outward from the global origin.
* The resulting array may be shorter than the input array - if a single projection is impossible it will not be included.
*
* @see EllipsoidTangentPlane.projectPointOntoPlane
*
* @param {Cartesian3[]} cartesians The array of points to project.
* @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.
* @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided.
*/
EllipsoidTangentPlane.prototype.projectPointsOntoPlane = function (
cartesians,
result,
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("cartesians", cartesians);
//>>includeEnd('debug');
if (!defined(result)) {
result = [];
}
let count = 0;
const length = cartesians.length;
for (let i = 0; i < length; i++) {
const p = this.projectPointOntoPlane(cartesians[i], result[count]);
if (defined(p)) {
result[count] = p;
count++;
}
}
result.length = count;
return result;
};
/**
* Computes the projection of the provided 3D position onto the 2D plane, along the plane normal.
*
* @param {Cartesian3} cartesian The point to project.
* @param {Cartesian2} [result] The object onto which to store the result.
* @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided.
*/
EllipsoidTangentPlane.prototype.projectPointToNearestOnPlane = function (
cartesian,
result,
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("cartesian", cartesian);
//>>includeEnd('debug');
if (!defined(result)) {
result = new Cartesian2();
}
const ray = scratchProjectPointOntoPlaneRay;
ray.origin = cartesian;
Cartesian3.clone(this._plane.normal, ray.direction);
let intersectionPoint = IntersectionTests.rayPlane(
ray,
this._plane,
scratchProjectPointOntoPlaneCartesian3,
);
if (!defined(intersectionPoint)) {
Cartesian3.negate(ray.direction, ray.direction);
intersectionPoint = IntersectionTests.rayPlane(
ray,
this._plane,
scratchProjectPointOntoPlaneCartesian3,
);
}
const v = Cartesian3.subtract(
intersectionPoint,
this._origin,
intersectionPoint,
);
const x = Cartesian3.dot(this._xAxis, v);
const y = Cartesian3.dot(this._yAxis, v);
result.x = x;
result.y = y;
return result;
};
/**
* Computes the projection of the provided 3D positions onto the 2D plane, along the plane normal.
*
* @see EllipsoidTangentPlane.projectPointToNearestOnPlane
*
* @param {Cartesian3[]} cartesians The array of points to project.
* @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.
* @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided. This will have the same length as <code>cartesians</code>.
*/
EllipsoidTangentPlane.prototype.projectPointsToNearestOnPlane = function (
cartesians,
result,
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("cartesians", cartesians);
//>>includeEnd('debug');
if (!defined(result)) {
result = [];
}
const length = cartesians.length;
result.length = length;
for (let i = 0; i < length; i++) {
result[i] = this.projectPointToNearestOnPlane(cartesians[i], result[i]);
}
return result;
};
const projectPointsOntoEllipsoidScratch = new Cartesian3();
/**
* Computes the projection of the provided 2D position onto the 3D ellipsoid.
*
* @param {Cartesian2} cartesian The points to project.
* @param {Cartesian3} [result] The Cartesian3 instance to store result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
*/
EllipsoidTangentPlane.prototype.projectPointOntoEllipsoid = function (
cartesian,
result,
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("cartesian", cartesian);
//>>includeEnd('debug');
if (!defined(result)) {
result = new Cartesian3();
}
const ellipsoid = this._ellipsoid;
const origin = this._origin;
const xAxis = this._xAxis;
const yAxis = this._yAxis;
const tmp = projectPointsOntoEllipsoidScratch;
Cartesian3.multiplyByScalar(xAxis, cartesian.x, tmp);
result = Cartesian3.add(origin, tmp, result);
Cartesian3.multiplyByScalar(yAxis, cartesian.y, tmp);
Cartesian3.add(result, tmp, result);
ellipsoid.scaleToGeocentricSurface(result, result);
return result;
};
/**
* Computes the projection of the provided 2D positions onto the 3D ellipsoid.
*
* @param {Cartesian2[]} cartesians The array of points to project.
* @param {Cartesian3[]} [result] The array of Cartesian3 instances onto which to store results.
* @returns {Cartesian3[]} The modified result parameter or a new array of Cartesian3 instances if none was provided.
*/
EllipsoidTangentPlane.prototype.projectPointsOntoEllipsoid = function (
cartesians,
result,
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("cartesians", cartesians);
//>>includeEnd('debug');
const length = cartesians.length;
if (!defined(result)) {
result = new Array(length);
} else {
result.length = length;
}
for (let i = 0; i < length; ++i) {
result[i] = this.projectPointOntoEllipsoid(cartesians[i], result[i]);
}
return result;
};
export default EllipsoidTangentPlane;
|