diff --git a/Source/Core/Cartesian2.js b/Source/Core/Cartesian2.js index 64a5ca0422bf..986b109eb4f4 100644 --- a/Source/Core/Cartesian2.js +++ b/Source/Core/Cartesian2.js @@ -406,6 +406,22 @@ Cartesian2.dot = function (left, right) { return left.x * right.x + left.y * right.y; }; +/** + * Computes the magnitude of the cross product that would result from implicitly setting the Z coordinate of the input vectors to 0 + * + * @param {Cartesian2} left The first Cartesian. + * @param {Cartesian2} right The second Cartesian. + * @returns {Number} The cross product. + */ +Cartesian2.cross = function (left, right) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object("left", left); + Check.typeOf.object("right", right); + //>>includeEnd('debug'); + + return left.x * right.y - left.y * right.x; +}; + /** * Computes the componentwise product of two Cartesians. * diff --git a/Specs/Core/Cartesian2Spec.js b/Specs/Core/Cartesian2Spec.js index 591d66f99f5d..305748e49161 100644 --- a/Specs/Core/Cartesian2Spec.js +++ b/Specs/Core/Cartesian2Spec.js @@ -402,6 +402,14 @@ describe("Core/Cartesian2", function () { expect(result).toEqual(expectedResult); }); + it("cross", function () { + var left = new Cartesian2(0.0, 1.0); + var right = new Cartesian2(1.0, 0.0); + var expectedResult = -1.0; + var result = Cartesian2.cross(left, right); + expect(result).toEqual(expectedResult); + }); + it("add works with a result parameter", function () { var left = new Cartesian2(2.0, 3.0); var right = new Cartesian2(4.0, 5.0);