12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283 |
- define(['exports', './Check-6ede7e26', './defaultValue-fe22d8c0', './Math-0a2ac845'], (function (exports, Check, defaultValue, Math$1) { 'use strict';
- /**
- * A 3D Cartesian point.
- * @alias Cartesian3
- * @constructor
- *
- * @param {number} [x=0.0] The X component.
- * @param {number} [y=0.0] The Y component.
- * @param {number} [z=0.0] The Z component.
- *
- * @see Cartesian2
- * @see Cartesian4
- * @see Packable
- */
- function Cartesian3(x, y, z) {
- /**
- * The X component.
- * @type {number}
- * @default 0.0
- */
- this.x = defaultValue.defaultValue(x, 0.0);
- /**
- * The Y component.
- * @type {number}
- * @default 0.0
- */
- this.y = defaultValue.defaultValue(y, 0.0);
- /**
- * The Z component.
- * @type {number}
- * @default 0.0
- */
- this.z = defaultValue.defaultValue(z, 0.0);
- }
- /**
- * Converts the provided Spherical into Cartesian3 coordinates.
- *
- * @param {Spherical} spherical The Spherical to be converted to Cartesian3.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
- */
- Cartesian3.fromSpherical = function (spherical, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("spherical", spherical);
- //>>includeEnd('debug');
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- const clock = spherical.clock;
- const cone = spherical.cone;
- const magnitude = defaultValue.defaultValue(spherical.magnitude, 1.0);
- const radial = magnitude * Math.sin(cone);
- result.x = radial * Math.cos(clock);
- result.y = radial * Math.sin(clock);
- result.z = magnitude * Math.cos(cone);
- return result;
- };
- /**
- * Creates a Cartesian3 instance from x, y and z coordinates.
- *
- * @param {number} x The x coordinate.
- * @param {number} y The y coordinate.
- * @param {number} z The z coordinate.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
- */
- Cartesian3.fromElements = function (x, y, z, result) {
- if (!defaultValue.defined(result)) {
- return new Cartesian3(x, y, z);
- }
- result.x = x;
- result.y = y;
- result.z = z;
- return result;
- };
- /**
- * Duplicates a Cartesian3 instance.
- *
- * @param {Cartesian3} cartesian The Cartesian to duplicate.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if cartesian is undefined)
- */
- Cartesian3.clone = function (cartesian, result) {
- if (!defaultValue.defined(cartesian)) {
- return undefined;
- }
- if (!defaultValue.defined(result)) {
- return new Cartesian3(cartesian.x, cartesian.y, cartesian.z);
- }
- result.x = cartesian.x;
- result.y = cartesian.y;
- result.z = cartesian.z;
- return result;
- };
- /**
- * Creates a Cartesian3 instance from an existing Cartesian4. This simply takes the
- * x, y, and z properties of the Cartesian4 and drops w.
- * @function
- *
- * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian3 instance from.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
- */
- Cartesian3.fromCartesian4 = Cartesian3.clone;
- /**
- * The number of elements used to pack the object into an array.
- * @type {number}
- */
- Cartesian3.packedLength = 3;
- /**
- * Stores the provided instance into the provided array.
- *
- * @param {Cartesian3} value The value to pack.
- * @param {number[]} array The array to pack into.
- * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
- *
- * @returns {number[]} The array that was packed into
- */
- Cartesian3.pack = function (value, array, startingIndex) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("value", value);
- Check.Check.defined("array", array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- array[startingIndex++] = value.x;
- array[startingIndex++] = value.y;
- array[startingIndex] = value.z;
- return array;
- };
- /**
- * Retrieves an instance from a packed array.
- *
- * @param {number[]} array The packed array.
- * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
- * @param {Cartesian3} [result] The object into which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
- */
- Cartesian3.unpack = function (array, startingIndex, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("array", array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- result.x = array[startingIndex++];
- result.y = array[startingIndex++];
- result.z = array[startingIndex];
- return result;
- };
- /**
- * Flattens an array of Cartesian3s into an array of components.
- *
- * @param {Cartesian3[]} array The array of cartesians to pack.
- * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 3 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 3) elements.
- * @returns {number[]} The packed array.
- */
- Cartesian3.packArray = function (array, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("array", array);
- //>>includeEnd('debug');
- const length = array.length;
- const resultLength = length * 3;
- if (!defaultValue.defined(result)) {
- result = new Array(resultLength);
- } else if (!Array.isArray(result) && result.length !== resultLength) {
- //>>includeStart('debug', pragmas.debug);
- throw new Check.DeveloperError(
- "If result is a typed array, it must have exactly array.length * 3 elements"
- );
- //>>includeEnd('debug');
- } else if (result.length !== resultLength) {
- result.length = resultLength;
- }
- for (let i = 0; i < length; ++i) {
- Cartesian3.pack(array[i], result, i * 3);
- }
- return result;
- };
- /**
- * Unpacks an array of cartesian components into an array of Cartesian3s.
- *
- * @param {number[]} array The array of components to unpack.
- * @param {Cartesian3[]} [result] The array onto which to store the result.
- * @returns {Cartesian3[]} The unpacked array.
- */
- Cartesian3.unpackArray = function (array, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("array", array);
- Check.Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 3);
- if (array.length % 3 !== 0) {
- throw new Check.DeveloperError("array length must be a multiple of 3.");
- }
- //>>includeEnd('debug');
- const length = array.length;
- if (!defaultValue.defined(result)) {
- result = new Array(length / 3);
- } else {
- result.length = length / 3;
- }
- for (let i = 0; i < length; i += 3) {
- const index = i / 3;
- result[index] = Cartesian3.unpack(array, i, result[index]);
- }
- return result;
- };
- /**
- * Creates a Cartesian3 from three consecutive elements in an array.
- * @function
- *
- * @param {number[]} array The array whose three consecutive elements correspond to the x, y, and z components, respectively.
- * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
- *
- * @example
- * // Create a Cartesian3 with (1.0, 2.0, 3.0)
- * const v = [1.0, 2.0, 3.0];
- * const p = Cesium.Cartesian3.fromArray(v);
- *
- * // Create a Cartesian3 with (1.0, 2.0, 3.0) using an offset into an array
- * const v2 = [0.0, 0.0, 1.0, 2.0, 3.0];
- * const p2 = Cesium.Cartesian3.fromArray(v2, 2);
- */
- Cartesian3.fromArray = Cartesian3.unpack;
- /**
- * Computes the value of the maximum component for the supplied Cartesian.
- *
- * @param {Cartesian3} cartesian The cartesian to use.
- * @returns {number} The value of the maximum component.
- */
- Cartesian3.maximumComponent = function (cartesian) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- //>>includeEnd('debug');
- return Math.max(cartesian.x, cartesian.y, cartesian.z);
- };
- /**
- * Computes the value of the minimum component for the supplied Cartesian.
- *
- * @param {Cartesian3} cartesian The cartesian to use.
- * @returns {number} The value of the minimum component.
- */
- Cartesian3.minimumComponent = function (cartesian) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- //>>includeEnd('debug');
- return Math.min(cartesian.x, cartesian.y, cartesian.z);
- };
- /**
- * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
- *
- * @param {Cartesian3} first A cartesian to compare.
- * @param {Cartesian3} second A cartesian to compare.
- * @param {Cartesian3} result The object into which to store the result.
- * @returns {Cartesian3} A cartesian with the minimum components.
- */
- Cartesian3.minimumByComponent = function (first, second, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("first", first);
- Check.Check.typeOf.object("second", second);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = Math.min(first.x, second.x);
- result.y = Math.min(first.y, second.y);
- result.z = Math.min(first.z, second.z);
- return result;
- };
- /**
- * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
- *
- * @param {Cartesian3} first A cartesian to compare.
- * @param {Cartesian3} second A cartesian to compare.
- * @param {Cartesian3} result The object into which to store the result.
- * @returns {Cartesian3} A cartesian with the maximum components.
- */
- Cartesian3.maximumByComponent = function (first, second, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("first", first);
- Check.Check.typeOf.object("second", second);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = Math.max(first.x, second.x);
- result.y = Math.max(first.y, second.y);
- result.z = Math.max(first.z, second.z);
- return result;
- };
- /**
- * Constrain a value to lie between two values.
- *
- * @param {Cartesian3} cartesian The value to clamp.
- * @param {Cartesian3} min The minimum bound.
- * @param {Cartesian3} max The maximum bound.
- * @param {Cartesian3} result The object into which to store the result.
- * @returns {Cartesian3} The clamped value such that min <= value <= max.
- */
- Cartesian3.clamp = function (value, min, max, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("value", value);
- Check.Check.typeOf.object("min", min);
- Check.Check.typeOf.object("max", max);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const x = Math$1.CesiumMath.clamp(value.x, min.x, max.x);
- const y = Math$1.CesiumMath.clamp(value.y, min.y, max.y);
- const z = Math$1.CesiumMath.clamp(value.z, min.z, max.z);
- result.x = x;
- result.y = y;
- result.z = z;
- return result;
- };
- /**
- * Computes the provided Cartesian's squared magnitude.
- *
- * @param {Cartesian3} cartesian The Cartesian instance whose squared magnitude is to be computed.
- * @returns {number} The squared magnitude.
- */
- Cartesian3.magnitudeSquared = function (cartesian) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- //>>includeEnd('debug');
- return (
- cartesian.x * cartesian.x +
- cartesian.y * cartesian.y +
- cartesian.z * cartesian.z
- );
- };
- /**
- * Computes the Cartesian's magnitude (length).
- *
- * @param {Cartesian3} cartesian The Cartesian instance whose magnitude is to be computed.
- * @returns {number} The magnitude.
- */
- Cartesian3.magnitude = function (cartesian) {
- return Math.sqrt(Cartesian3.magnitudeSquared(cartesian));
- };
- const distanceScratch = new Cartesian3();
- /**
- * Computes the distance between two points.
- *
- * @param {Cartesian3} left The first point to compute the distance from.
- * @param {Cartesian3} right The second point to compute the distance to.
- * @returns {number} The distance between two points.
- *
- * @example
- * // Returns 1.0
- * const d = Cesium.Cartesian3.distance(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(2.0, 0.0, 0.0));
- */
- Cartesian3.distance = function (left, right) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- //>>includeEnd('debug');
- Cartesian3.subtract(left, right, distanceScratch);
- return Cartesian3.magnitude(distanceScratch);
- };
- /**
- * Computes the squared distance between two points. Comparing squared distances
- * using this function is more efficient than comparing distances using {@link Cartesian3#distance}.
- *
- * @param {Cartesian3} left The first point to compute the distance from.
- * @param {Cartesian3} right The second point to compute the distance to.
- * @returns {number} The distance between two points.
- *
- * @example
- * // Returns 4.0, not 2.0
- * const d = Cesium.Cartesian3.distanceSquared(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(3.0, 0.0, 0.0));
- */
- Cartesian3.distanceSquared = function (left, right) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- //>>includeEnd('debug');
- Cartesian3.subtract(left, right, distanceScratch);
- return Cartesian3.magnitudeSquared(distanceScratch);
- };
- /**
- * Computes the normalized form of the supplied Cartesian.
- *
- * @param {Cartesian3} cartesian The Cartesian to be normalized.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.normalize = function (cartesian, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const magnitude = Cartesian3.magnitude(cartesian);
- result.x = cartesian.x / magnitude;
- result.y = cartesian.y / magnitude;
- result.z = cartesian.z / magnitude;
- //>>includeStart('debug', pragmas.debug);
- if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
- throw new Check.DeveloperError("normalized result is not a number");
- }
- //>>includeEnd('debug');
- return result;
- };
- /**
- * Computes the dot (scalar) product of two Cartesians.
- *
- * @param {Cartesian3} left The first Cartesian.
- * @param {Cartesian3} right The second Cartesian.
- * @returns {number} The dot product.
- */
- Cartesian3.dot = function (left, right) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- //>>includeEnd('debug');
- return left.x * right.x + left.y * right.y + left.z * right.z;
- };
- /**
- * Computes the componentwise product of two Cartesians.
- *
- * @param {Cartesian3} left The first Cartesian.
- * @param {Cartesian3} right The second Cartesian.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.multiplyComponents = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = left.x * right.x;
- result.y = left.y * right.y;
- result.z = left.z * right.z;
- return result;
- };
- /**
- * Computes the componentwise quotient of two Cartesians.
- *
- * @param {Cartesian3} left The first Cartesian.
- * @param {Cartesian3} right The second Cartesian.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.divideComponents = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = left.x / right.x;
- result.y = left.y / right.y;
- result.z = left.z / right.z;
- return result;
- };
- /**
- * Computes the componentwise sum of two Cartesians.
- *
- * @param {Cartesian3} left The first Cartesian.
- * @param {Cartesian3} right The second Cartesian.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.add = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = left.x + right.x;
- result.y = left.y + right.y;
- result.z = left.z + right.z;
- return result;
- };
- /**
- * Computes the componentwise difference of two Cartesians.
- *
- * @param {Cartesian3} left The first Cartesian.
- * @param {Cartesian3} right The second Cartesian.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.subtract = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = left.x - right.x;
- result.y = left.y - right.y;
- result.z = left.z - right.z;
- return result;
- };
- /**
- * Multiplies the provided Cartesian componentwise by the provided scalar.
- *
- * @param {Cartesian3} cartesian The Cartesian to be scaled.
- * @param {number} scalar The scalar to multiply with.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.multiplyByScalar = function (cartesian, scalar, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.number("scalar", scalar);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = cartesian.x * scalar;
- result.y = cartesian.y * scalar;
- result.z = cartesian.z * scalar;
- return result;
- };
- /**
- * Divides the provided Cartesian componentwise by the provided scalar.
- *
- * @param {Cartesian3} cartesian The Cartesian to be divided.
- * @param {number} scalar The scalar to divide by.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.divideByScalar = function (cartesian, scalar, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.number("scalar", scalar);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = cartesian.x / scalar;
- result.y = cartesian.y / scalar;
- result.z = cartesian.z / scalar;
- return result;
- };
- /**
- * Negates the provided Cartesian.
- *
- * @param {Cartesian3} cartesian The Cartesian to be negated.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.negate = function (cartesian, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = -cartesian.x;
- result.y = -cartesian.y;
- result.z = -cartesian.z;
- return result;
- };
- /**
- * Computes the absolute value of the provided Cartesian.
- *
- * @param {Cartesian3} cartesian The Cartesian whose absolute value is to be computed.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.abs = function (cartesian, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = Math.abs(cartesian.x);
- result.y = Math.abs(cartesian.y);
- result.z = Math.abs(cartesian.z);
- return result;
- };
- const lerpScratch = new Cartesian3();
- /**
- * Computes the linear interpolation or extrapolation at t using the provided cartesians.
- *
- * @param {Cartesian3} start The value corresponding to t at 0.0.
- * @param {Cartesian3} end The value corresponding to t at 1.0.
- * @param {number} t The point along t at which to interpolate.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Cartesian3.lerp = function (start, end, t, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("start", start);
- Check.Check.typeOf.object("end", end);
- Check.Check.typeOf.number("t", t);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- Cartesian3.multiplyByScalar(end, t, lerpScratch);
- result = Cartesian3.multiplyByScalar(start, 1.0 - t, result);
- return Cartesian3.add(lerpScratch, result, result);
- };
- const angleBetweenScratch = new Cartesian3();
- const angleBetweenScratch2 = new Cartesian3();
- /**
- * Returns the angle, in radians, between the provided Cartesians.
- *
- * @param {Cartesian3} left The first Cartesian.
- * @param {Cartesian3} right The second Cartesian.
- * @returns {number} The angle between the Cartesians.
- */
- Cartesian3.angleBetween = function (left, right) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- //>>includeEnd('debug');
- Cartesian3.normalize(left, angleBetweenScratch);
- Cartesian3.normalize(right, angleBetweenScratch2);
- const cosine = Cartesian3.dot(angleBetweenScratch, angleBetweenScratch2);
- const sine = Cartesian3.magnitude(
- Cartesian3.cross(
- angleBetweenScratch,
- angleBetweenScratch2,
- angleBetweenScratch
- )
- );
- return Math.atan2(sine, cosine);
- };
- const mostOrthogonalAxisScratch = new Cartesian3();
- /**
- * Returns the axis that is most orthogonal to the provided Cartesian.
- *
- * @param {Cartesian3} cartesian The Cartesian on which to find the most orthogonal axis.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The most orthogonal axis.
- */
- Cartesian3.mostOrthogonalAxis = function (cartesian, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const f = Cartesian3.normalize(cartesian, mostOrthogonalAxisScratch);
- Cartesian3.abs(f, f);
- if (f.x <= f.y) {
- if (f.x <= f.z) {
- result = Cartesian3.clone(Cartesian3.UNIT_X, result);
- } else {
- result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
- }
- } else if (f.y <= f.z) {
- result = Cartesian3.clone(Cartesian3.UNIT_Y, result);
- } else {
- result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
- }
- return result;
- };
- /**
- * Projects vector a onto vector b
- * @param {Cartesian3} a The vector that needs projecting
- * @param {Cartesian3} b The vector to project onto
- * @param {Cartesian3} result The result cartesian
- * @returns {Cartesian3} The modified result parameter
- */
- Cartesian3.projectVector = function (a, b, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("a", a);
- Check.Check.defined("b", b);
- Check.Check.defined("result", result);
- //>>includeEnd('debug');
- const scalar = Cartesian3.dot(a, b) / Cartesian3.dot(b, b);
- return Cartesian3.multiplyByScalar(b, scalar, result);
- };
- /**
- * Compares the provided Cartesians componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {Cartesian3} [left] The first Cartesian.
- * @param {Cartesian3} [right] The second Cartesian.
- * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
- */
- Cartesian3.equals = function (left, right) {
- return (
- left === right ||
- (defaultValue.defined(left) &&
- defaultValue.defined(right) &&
- left.x === right.x &&
- left.y === right.y &&
- left.z === right.z)
- );
- };
- /**
- * @private
- */
- Cartesian3.equalsArray = function (cartesian, array, offset) {
- return (
- cartesian.x === array[offset] &&
- cartesian.y === array[offset + 1] &&
- cartesian.z === array[offset + 2]
- );
- };
- /**
- * Compares the provided Cartesians componentwise and returns
- * <code>true</code> if they pass an absolute or relative tolerance test,
- * <code>false</code> otherwise.
- *
- * @param {Cartesian3} [left] The first Cartesian.
- * @param {Cartesian3} [right] The second Cartesian.
- * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
- * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
- * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
- */
- Cartesian3.equalsEpsilon = function (
- left,
- right,
- relativeEpsilon,
- absoluteEpsilon
- ) {
- return (
- left === right ||
- (defaultValue.defined(left) &&
- defaultValue.defined(right) &&
- Math$1.CesiumMath.equalsEpsilon(
- left.x,
- right.x,
- relativeEpsilon,
- absoluteEpsilon
- ) &&
- Math$1.CesiumMath.equalsEpsilon(
- left.y,
- right.y,
- relativeEpsilon,
- absoluteEpsilon
- ) &&
- Math$1.CesiumMath.equalsEpsilon(
- left.z,
- right.z,
- relativeEpsilon,
- absoluteEpsilon
- ))
- );
- };
- /**
- * Computes the cross (outer) product of two Cartesians.
- *
- * @param {Cartesian3} left The first Cartesian.
- * @param {Cartesian3} right The second Cartesian.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The cross product.
- */
- Cartesian3.cross = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const leftX = left.x;
- const leftY = left.y;
- const leftZ = left.z;
- const rightX = right.x;
- const rightY = right.y;
- const rightZ = right.z;
- const x = leftY * rightZ - leftZ * rightY;
- const y = leftZ * rightX - leftX * rightZ;
- const z = leftX * rightY - leftY * rightX;
- result.x = x;
- result.y = y;
- result.z = z;
- return result;
- };
- /**
- * Computes the midpoint between the right and left Cartesian.
- * @param {Cartesian3} left The first Cartesian.
- * @param {Cartesian3} right The second Cartesian.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The midpoint.
- */
- Cartesian3.midpoint = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = (left.x + right.x) * 0.5;
- result.y = (left.y + right.y) * 0.5;
- result.z = (left.z + right.z) * 0.5;
- return result;
- };
- /**
- * Returns a Cartesian3 position from longitude and latitude values given in degrees.
- *
- * @param {number} longitude The longitude, in degrees
- * @param {number} latitude The latitude, in degrees
- * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The position
- *
- * @example
- * const position = Cesium.Cartesian3.fromDegrees(-115.0, 37.0);
- */
- Cartesian3.fromDegrees = function (
- longitude,
- latitude,
- height,
- ellipsoid,
- result
- ) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("longitude", longitude);
- Check.Check.typeOf.number("latitude", latitude);
- //>>includeEnd('debug');
- longitude = Math$1.CesiumMath.toRadians(longitude);
- latitude = Math$1.CesiumMath.toRadians(latitude);
- return Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result);
- };
- let scratchN = new Cartesian3();
- let scratchK = new Cartesian3();
- const wgs84RadiiSquared = new Cartesian3(
- 6378137.0 * 6378137.0,
- 6378137.0 * 6378137.0,
- 6356752.3142451793 * 6356752.3142451793
- );
- /**
- * Returns a Cartesian3 position from longitude and latitude values given in radians.
- *
- * @param {number} longitude The longitude, in radians
- * @param {number} latitude The latitude, in radians
- * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The position
- *
- * @example
- * const position = Cesium.Cartesian3.fromRadians(-2.007, 0.645);
- */
- Cartesian3.fromRadians = function (
- longitude,
- latitude,
- height,
- ellipsoid,
- result
- ) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("longitude", longitude);
- Check.Check.typeOf.number("latitude", latitude);
- //>>includeEnd('debug');
- height = defaultValue.defaultValue(height, 0.0);
- const radiiSquared = defaultValue.defined(ellipsoid)
- ? ellipsoid.radiiSquared
- : wgs84RadiiSquared;
- const cosLatitude = Math.cos(latitude);
- scratchN.x = cosLatitude * Math.cos(longitude);
- scratchN.y = cosLatitude * Math.sin(longitude);
- scratchN.z = Math.sin(latitude);
- scratchN = Cartesian3.normalize(scratchN, scratchN);
- Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK);
- const gamma = Math.sqrt(Cartesian3.dot(scratchN, scratchK));
- scratchK = Cartesian3.divideByScalar(scratchK, gamma, scratchK);
- scratchN = Cartesian3.multiplyByScalar(scratchN, height, scratchN);
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- return Cartesian3.add(scratchK, scratchN, result);
- };
- /**
- * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.
- *
- * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.
- * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
- * @returns {Cartesian3[]} The array of positions.
- *
- * @example
- * const positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0, -107.0, 33.0]);
- */
- Cartesian3.fromDegreesArray = function (coordinates, ellipsoid, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("coordinates", coordinates);
- if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
- throw new Check.DeveloperError(
- "the number of coordinates must be a multiple of 2 and at least 2"
- );
- }
- //>>includeEnd('debug');
- const length = coordinates.length;
- if (!defaultValue.defined(result)) {
- result = new Array(length / 2);
- } else {
- result.length = length / 2;
- }
- for (let i = 0; i < length; i += 2) {
- const longitude = coordinates[i];
- const latitude = coordinates[i + 1];
- const index = i / 2;
- result[index] = Cartesian3.fromDegrees(
- longitude,
- latitude,
- 0,
- ellipsoid,
- result[index]
- );
- }
- return result;
- };
- /**
- * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.
- *
- * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.
- * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
- * @returns {Cartesian3[]} The array of positions.
- *
- * @example
- * const positions = Cesium.Cartesian3.fromRadiansArray([-2.007, 0.645, -1.867, .575]);
- */
- Cartesian3.fromRadiansArray = function (coordinates, ellipsoid, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("coordinates", coordinates);
- if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
- throw new Check.DeveloperError(
- "the number of coordinates must be a multiple of 2 and at least 2"
- );
- }
- //>>includeEnd('debug');
- const length = coordinates.length;
- if (!defaultValue.defined(result)) {
- result = new Array(length / 2);
- } else {
- result.length = length / 2;
- }
- for (let i = 0; i < length; i += 2) {
- const longitude = coordinates[i];
- const latitude = coordinates[i + 1];
- const index = i / 2;
- result[index] = Cartesian3.fromRadians(
- longitude,
- latitude,
- 0,
- ellipsoid,
- result[index]
- );
- }
- return result;
- };
- /**
- * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.
- *
- * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
- * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
- * @returns {Cartesian3[]} The array of positions.
- *
- * @example
- * const positions = Cesium.Cartesian3.fromDegreesArrayHeights([-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]);
- */
- Cartesian3.fromDegreesArrayHeights = function (coordinates, ellipsoid, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("coordinates", coordinates);
- if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
- throw new Check.DeveloperError(
- "the number of coordinates must be a multiple of 3 and at least 3"
- );
- }
- //>>includeEnd('debug');
- const length = coordinates.length;
- if (!defaultValue.defined(result)) {
- result = new Array(length / 3);
- } else {
- result.length = length / 3;
- }
- for (let i = 0; i < length; i += 3) {
- const longitude = coordinates[i];
- const latitude = coordinates[i + 1];
- const height = coordinates[i + 2];
- const index = i / 3;
- result[index] = Cartesian3.fromDegrees(
- longitude,
- latitude,
- height,
- ellipsoid,
- result[index]
- );
- }
- return result;
- };
- /**
- * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.
- *
- * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
- * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
- * @returns {Cartesian3[]} The array of positions.
- *
- * @example
- * const positions = Cesium.Cartesian3.fromRadiansArrayHeights([-2.007, 0.645, 100000.0, -1.867, .575, 150000.0]);
- */
- Cartesian3.fromRadiansArrayHeights = function (coordinates, ellipsoid, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("coordinates", coordinates);
- if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
- throw new Check.DeveloperError(
- "the number of coordinates must be a multiple of 3 and at least 3"
- );
- }
- //>>includeEnd('debug');
- const length = coordinates.length;
- if (!defaultValue.defined(result)) {
- result = new Array(length / 3);
- } else {
- result.length = length / 3;
- }
- for (let i = 0; i < length; i += 3) {
- const longitude = coordinates[i];
- const latitude = coordinates[i + 1];
- const height = coordinates[i + 2];
- const index = i / 3;
- result[index] = Cartesian3.fromRadians(
- longitude,
- latitude,
- height,
- ellipsoid,
- result[index]
- );
- }
- return result;
- };
- /**
- * An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0).
- *
- * @type {Cartesian3}
- * @constant
- */
- Cartesian3.ZERO = Object.freeze(new Cartesian3(0.0, 0.0, 0.0));
- /**
- * An immutable Cartesian3 instance initialized to (1.0, 1.0, 1.0).
- *
- * @type {Cartesian3}
- * @constant
- */
- Cartesian3.ONE = Object.freeze(new Cartesian3(1.0, 1.0, 1.0));
- /**
- * An immutable Cartesian3 instance initialized to (1.0, 0.0, 0.0).
- *
- * @type {Cartesian3}
- * @constant
- */
- Cartesian3.UNIT_X = Object.freeze(new Cartesian3(1.0, 0.0, 0.0));
- /**
- * An immutable Cartesian3 instance initialized to (0.0, 1.0, 0.0).
- *
- * @type {Cartesian3}
- * @constant
- */
- Cartesian3.UNIT_Y = Object.freeze(new Cartesian3(0.0, 1.0, 0.0));
- /**
- * An immutable Cartesian3 instance initialized to (0.0, 0.0, 1.0).
- *
- * @type {Cartesian3}
- * @constant
- */
- Cartesian3.UNIT_Z = Object.freeze(new Cartesian3(0.0, 0.0, 1.0));
- /**
- * Duplicates this Cartesian3 instance.
- *
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
- */
- Cartesian3.prototype.clone = function (result) {
- return Cartesian3.clone(this, result);
- };
- /**
- * Compares this Cartesian against the provided Cartesian componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {Cartesian3} [right] The right hand side Cartesian.
- * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
- */
- Cartesian3.prototype.equals = function (right) {
- return Cartesian3.equals(this, right);
- };
- /**
- * Compares this Cartesian against the provided Cartesian componentwise and returns
- * <code>true</code> if they pass an absolute or relative tolerance test,
- * <code>false</code> otherwise.
- *
- * @param {Cartesian3} [right] The right hand side Cartesian.
- * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
- * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
- * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
- */
- Cartesian3.prototype.equalsEpsilon = function (
- right,
- relativeEpsilon,
- absoluteEpsilon
- ) {
- return Cartesian3.equalsEpsilon(
- this,
- right,
- relativeEpsilon,
- absoluteEpsilon
- );
- };
- /**
- * Creates a string representing this Cartesian in the format '(x, y, z)'.
- *
- * @returns {string} A string representing this Cartesian in the format '(x, y, z)'.
- */
- Cartesian3.prototype.toString = function () {
- return `(${this.x}, ${this.y}, ${this.z})`;
- };
- const scaleToGeodeticSurfaceIntersection = new Cartesian3();
- const scaleToGeodeticSurfaceGradient = new Cartesian3();
- /**
- * Scales the provided Cartesian position along the geodetic surface normal
- * so that it is on the surface of this ellipsoid. If the position is
- * at the center of the ellipsoid, this function returns undefined.
- *
- * @param {Cartesian3} cartesian The Cartesian position to scale.
- * @param {Cartesian3} oneOverRadii One over radii of the ellipsoid.
- * @param {Cartesian3} oneOverRadiiSquared One over radii squared of the ellipsoid.
- * @param {number} centerToleranceSquared Tolerance for closeness to the center.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.
- *
- * @function scaleToGeodeticSurface
- *
- * @private
- */
- function scaleToGeodeticSurface(
- cartesian,
- oneOverRadii,
- oneOverRadiiSquared,
- centerToleranceSquared,
- result
- ) {
- //>>includeStart('debug', pragmas.debug);
- if (!defaultValue.defined(cartesian)) {
- throw new Check.DeveloperError("cartesian is required.");
- }
- if (!defaultValue.defined(oneOverRadii)) {
- throw new Check.DeveloperError("oneOverRadii is required.");
- }
- if (!defaultValue.defined(oneOverRadiiSquared)) {
- throw new Check.DeveloperError("oneOverRadiiSquared is required.");
- }
- if (!defaultValue.defined(centerToleranceSquared)) {
- throw new Check.DeveloperError("centerToleranceSquared is required.");
- }
- //>>includeEnd('debug');
- const positionX = cartesian.x;
- const positionY = cartesian.y;
- const positionZ = cartesian.z;
- const oneOverRadiiX = oneOverRadii.x;
- const oneOverRadiiY = oneOverRadii.y;
- const oneOverRadiiZ = oneOverRadii.z;
- const x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;
- const y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;
- const z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;
- // Compute the squared ellipsoid norm.
- const squaredNorm = x2 + y2 + z2;
- const ratio = Math.sqrt(1.0 / squaredNorm);
- // As an initial approximation, assume that the radial intersection is the projection point.
- const intersection = Cartesian3.multiplyByScalar(
- cartesian,
- ratio,
- scaleToGeodeticSurfaceIntersection
- );
- // If the position is near the center, the iteration will not converge.
- if (squaredNorm < centerToleranceSquared) {
- return !isFinite(ratio)
- ? undefined
- : Cartesian3.clone(intersection, result);
- }
- const oneOverRadiiSquaredX = oneOverRadiiSquared.x;
- const oneOverRadiiSquaredY = oneOverRadiiSquared.y;
- const oneOverRadiiSquaredZ = oneOverRadiiSquared.z;
- // Use the gradient at the intersection point in place of the true unit normal.
- // The difference in magnitude will be absorbed in the multiplier.
- const gradient = scaleToGeodeticSurfaceGradient;
- gradient.x = intersection.x * oneOverRadiiSquaredX * 2.0;
- gradient.y = intersection.y * oneOverRadiiSquaredY * 2.0;
- gradient.z = intersection.z * oneOverRadiiSquaredZ * 2.0;
- // Compute the initial guess at the normal vector multiplier, lambda.
- let lambda =
- ((1.0 - ratio) * Cartesian3.magnitude(cartesian)) /
- (0.5 * Cartesian3.magnitude(gradient));
- let correction = 0.0;
- let func;
- let denominator;
- let xMultiplier;
- let yMultiplier;
- let zMultiplier;
- let xMultiplier2;
- let yMultiplier2;
- let zMultiplier2;
- let xMultiplier3;
- let yMultiplier3;
- let zMultiplier3;
- do {
- lambda -= correction;
- xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);
- yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);
- zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);
- xMultiplier2 = xMultiplier * xMultiplier;
- yMultiplier2 = yMultiplier * yMultiplier;
- zMultiplier2 = zMultiplier * zMultiplier;
- xMultiplier3 = xMultiplier2 * xMultiplier;
- yMultiplier3 = yMultiplier2 * yMultiplier;
- zMultiplier3 = zMultiplier2 * zMultiplier;
- func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;
- // "denominator" here refers to the use of this expression in the velocity and acceleration
- // computations in the sections to follow.
- denominator =
- x2 * xMultiplier3 * oneOverRadiiSquaredX +
- y2 * yMultiplier3 * oneOverRadiiSquaredY +
- z2 * zMultiplier3 * oneOverRadiiSquaredZ;
- const derivative = -2.0 * denominator;
- correction = func / derivative;
- } while (Math.abs(func) > Math$1.CesiumMath.EPSILON12);
- if (!defaultValue.defined(result)) {
- return new Cartesian3(
- positionX * xMultiplier,
- positionY * yMultiplier,
- positionZ * zMultiplier
- );
- }
- result.x = positionX * xMultiplier;
- result.y = positionY * yMultiplier;
- result.z = positionZ * zMultiplier;
- return result;
- }
- /**
- * A position defined by longitude, latitude, and height.
- * @alias Cartographic
- * @constructor
- *
- * @param {number} [longitude=0.0] The longitude, in radians.
- * @param {number} [latitude=0.0] The latitude, in radians.
- * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
- *
- * @see Ellipsoid
- */
- function Cartographic(longitude, latitude, height) {
- /**
- * The longitude, in radians.
- * @type {number}
- * @default 0.0
- */
- this.longitude = defaultValue.defaultValue(longitude, 0.0);
- /**
- * The latitude, in radians.
- * @type {number}
- * @default 0.0
- */
- this.latitude = defaultValue.defaultValue(latitude, 0.0);
- /**
- * The height, in meters, above the ellipsoid.
- * @type {number}
- * @default 0.0
- */
- this.height = defaultValue.defaultValue(height, 0.0);
- }
- /**
- * Creates a new Cartographic instance from longitude and latitude
- * specified in radians.
- *
- * @param {number} longitude The longitude, in radians.
- * @param {number} latitude The latitude, in radians.
- * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
- * @param {Cartographic} [result] The object onto which to store the result.
- * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
- */
- Cartographic.fromRadians = function (longitude, latitude, height, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("longitude", longitude);
- Check.Check.typeOf.number("latitude", latitude);
- //>>includeEnd('debug');
- height = defaultValue.defaultValue(height, 0.0);
- if (!defaultValue.defined(result)) {
- return new Cartographic(longitude, latitude, height);
- }
- result.longitude = longitude;
- result.latitude = latitude;
- result.height = height;
- return result;
- };
- /**
- * Creates a new Cartographic instance from longitude and latitude
- * specified in degrees. The values in the resulting object will
- * be in radians.
- *
- * @param {number} longitude The longitude, in degrees.
- * @param {number} latitude The latitude, in degrees.
- * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
- * @param {Cartographic} [result] The object onto which to store the result.
- * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
- */
- Cartographic.fromDegrees = function (longitude, latitude, height, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("longitude", longitude);
- Check.Check.typeOf.number("latitude", latitude);
- //>>includeEnd('debug');
- longitude = Math$1.CesiumMath.toRadians(longitude);
- latitude = Math$1.CesiumMath.toRadians(latitude);
- return Cartographic.fromRadians(longitude, latitude, height, result);
- };
- const cartesianToCartographicN$1 = new Cartesian3();
- const cartesianToCartographicP$1 = new Cartesian3();
- const cartesianToCartographicH$1 = new Cartesian3();
- const wgs84OneOverRadii = new Cartesian3(
- 1.0 / 6378137.0,
- 1.0 / 6378137.0,
- 1.0 / 6356752.3142451793
- );
- const wgs84OneOverRadiiSquared = new Cartesian3(
- 1.0 / (6378137.0 * 6378137.0),
- 1.0 / (6378137.0 * 6378137.0),
- 1.0 / (6356752.3142451793 * 6356752.3142451793)
- );
- const wgs84CenterToleranceSquared = Math$1.CesiumMath.EPSILON1;
- /**
- * Creates a new Cartographic instance from a Cartesian position. The values in the
- * resulting object will be in radians.
- *
- * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
- * @param {Cartographic} [result] The object onto which to store the result.
- * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
- */
- Cartographic.fromCartesian = function (cartesian, ellipsoid, result) {
- const oneOverRadii = defaultValue.defined(ellipsoid)
- ? ellipsoid.oneOverRadii
- : wgs84OneOverRadii;
- const oneOverRadiiSquared = defaultValue.defined(ellipsoid)
- ? ellipsoid.oneOverRadiiSquared
- : wgs84OneOverRadiiSquared;
- const centerToleranceSquared = defaultValue.defined(ellipsoid)
- ? ellipsoid._centerToleranceSquared
- : wgs84CenterToleranceSquared;
- //`cartesian is required.` is thrown from scaleToGeodeticSurface
- const p = scaleToGeodeticSurface(
- cartesian,
- oneOverRadii,
- oneOverRadiiSquared,
- centerToleranceSquared,
- cartesianToCartographicP$1
- );
- if (!defaultValue.defined(p)) {
- return undefined;
- }
- let n = Cartesian3.multiplyComponents(
- p,
- oneOverRadiiSquared,
- cartesianToCartographicN$1
- );
- n = Cartesian3.normalize(n, n);
- const h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH$1);
- const longitude = Math.atan2(n.y, n.x);
- const latitude = Math.asin(n.z);
- const height =
- Math$1.CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);
- if (!defaultValue.defined(result)) {
- return new Cartographic(longitude, latitude, height);
- }
- result.longitude = longitude;
- result.latitude = latitude;
- result.height = height;
- return result;
- };
- /**
- * Creates a new Cartesian3 instance from a Cartographic input. The values in the inputted
- * object should be in radians.
- *
- * @param {Cartographic} cartographic Input to be converted into a Cartesian3 output.
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The position
- */
- Cartographic.toCartesian = function (cartographic, ellipsoid, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("cartographic", cartographic);
- //>>includeEnd('debug');
- return Cartesian3.fromRadians(
- cartographic.longitude,
- cartographic.latitude,
- cartographic.height,
- ellipsoid,
- result
- );
- };
- /**
- * Duplicates a Cartographic instance.
- *
- * @param {Cartographic} cartographic The cartographic to duplicate.
- * @param {Cartographic} [result] The object onto which to store the result.
- * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided. (Returns undefined if cartographic is undefined)
- */
- Cartographic.clone = function (cartographic, result) {
- if (!defaultValue.defined(cartographic)) {
- return undefined;
- }
- if (!defaultValue.defined(result)) {
- return new Cartographic(
- cartographic.longitude,
- cartographic.latitude,
- cartographic.height
- );
- }
- result.longitude = cartographic.longitude;
- result.latitude = cartographic.latitude;
- result.height = cartographic.height;
- return result;
- };
- /**
- * Compares the provided cartographics componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {Cartographic} [left] The first cartographic.
- * @param {Cartographic} [right] The second cartographic.
- * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
- */
- Cartographic.equals = function (left, right) {
- return (
- left === right ||
- (defaultValue.defined(left) &&
- defaultValue.defined(right) &&
- left.longitude === right.longitude &&
- left.latitude === right.latitude &&
- left.height === right.height)
- );
- };
- /**
- * Compares the provided cartographics componentwise and returns
- * <code>true</code> if they are within the provided epsilon,
- * <code>false</code> otherwise.
- *
- * @param {Cartographic} [left] The first cartographic.
- * @param {Cartographic} [right] The second cartographic.
- * @param {number} [epsilon=0] The epsilon to use for equality testing.
- * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
- */
- Cartographic.equalsEpsilon = function (left, right, epsilon) {
- epsilon = defaultValue.defaultValue(epsilon, 0);
- return (
- left === right ||
- (defaultValue.defined(left) &&
- defaultValue.defined(right) &&
- Math.abs(left.longitude - right.longitude) <= epsilon &&
- Math.abs(left.latitude - right.latitude) <= epsilon &&
- Math.abs(left.height - right.height) <= epsilon)
- );
- };
- /**
- * An immutable Cartographic instance initialized to (0.0, 0.0, 0.0).
- *
- * @type {Cartographic}
- * @constant
- */
- Cartographic.ZERO = Object.freeze(new Cartographic(0.0, 0.0, 0.0));
- /**
- * Duplicates this instance.
- *
- * @param {Cartographic} [result] The object onto which to store the result.
- * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
- */
- Cartographic.prototype.clone = function (result) {
- return Cartographic.clone(this, result);
- };
- /**
- * Compares the provided against this cartographic componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {Cartographic} [right] The second cartographic.
- * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
- */
- Cartographic.prototype.equals = function (right) {
- return Cartographic.equals(this, right);
- };
- /**
- * Compares the provided against this cartographic componentwise and returns
- * <code>true</code> if they are within the provided epsilon,
- * <code>false</code> otherwise.
- *
- * @param {Cartographic} [right] The second cartographic.
- * @param {number} [epsilon=0] The epsilon to use for equality testing.
- * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
- */
- Cartographic.prototype.equalsEpsilon = function (right, epsilon) {
- return Cartographic.equalsEpsilon(this, right, epsilon);
- };
- /**
- * Creates a string representing this cartographic in the format '(longitude, latitude, height)'.
- *
- * @returns {string} A string representing the provided cartographic in the format '(longitude, latitude, height)'.
- */
- Cartographic.prototype.toString = function () {
- return `(${this.longitude}, ${this.latitude}, ${this.height})`;
- };
- function initialize(ellipsoid, x, y, z) {
- x = defaultValue.defaultValue(x, 0.0);
- y = defaultValue.defaultValue(y, 0.0);
- z = defaultValue.defaultValue(z, 0.0);
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number.greaterThanOrEquals("x", x, 0.0);
- Check.Check.typeOf.number.greaterThanOrEquals("y", y, 0.0);
- Check.Check.typeOf.number.greaterThanOrEquals("z", z, 0.0);
- //>>includeEnd('debug');
- ellipsoid._radii = new Cartesian3(x, y, z);
- ellipsoid._radiiSquared = new Cartesian3(x * x, y * y, z * z);
- ellipsoid._radiiToTheFourth = new Cartesian3(
- x * x * x * x,
- y * y * y * y,
- z * z * z * z
- );
- ellipsoid._oneOverRadii = new Cartesian3(
- x === 0.0 ? 0.0 : 1.0 / x,
- y === 0.0 ? 0.0 : 1.0 / y,
- z === 0.0 ? 0.0 : 1.0 / z
- );
- ellipsoid._oneOverRadiiSquared = new Cartesian3(
- x === 0.0 ? 0.0 : 1.0 / (x * x),
- y === 0.0 ? 0.0 : 1.0 / (y * y),
- z === 0.0 ? 0.0 : 1.0 / (z * z)
- );
- ellipsoid._minimumRadius = Math.min(x, y, z);
- ellipsoid._maximumRadius = Math.max(x, y, z);
- ellipsoid._centerToleranceSquared = Math$1.CesiumMath.EPSILON1;
- if (ellipsoid._radiiSquared.z !== 0) {
- ellipsoid._squaredXOverSquaredZ =
- ellipsoid._radiiSquared.x / ellipsoid._radiiSquared.z;
- }
- }
- /**
- * A quadratic surface defined in Cartesian coordinates by the equation
- * <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used
- * by Cesium to represent the shape of planetary bodies.
- *
- * Rather than constructing this object directly, one of the provided
- * constants is normally used.
- * @alias Ellipsoid
- * @constructor
- *
- * @param {number} [x=0] The radius in the x direction.
- * @param {number} [y=0] The radius in the y direction.
- * @param {number} [z=0] The radius in the z direction.
- *
- * @exception {DeveloperError} All radii components must be greater than or equal to zero.
- *
- * @see Ellipsoid.fromCartesian3
- * @see Ellipsoid.WGS84
- * @see Ellipsoid.UNIT_SPHERE
- */
- function Ellipsoid(x, y, z) {
- this._radii = undefined;
- this._radiiSquared = undefined;
- this._radiiToTheFourth = undefined;
- this._oneOverRadii = undefined;
- this._oneOverRadiiSquared = undefined;
- this._minimumRadius = undefined;
- this._maximumRadius = undefined;
- this._centerToleranceSquared = undefined;
- this._squaredXOverSquaredZ = undefined;
- initialize(this, x, y, z);
- }
- Object.defineProperties(Ellipsoid.prototype, {
- /**
- * Gets the radii of the ellipsoid.
- * @memberof Ellipsoid.prototype
- * @type {Cartesian3}
- * @readonly
- */
- radii: {
- get: function () {
- return this._radii;
- },
- },
- /**
- * Gets the squared radii of the ellipsoid.
- * @memberof Ellipsoid.prototype
- * @type {Cartesian3}
- * @readonly
- */
- radiiSquared: {
- get: function () {
- return this._radiiSquared;
- },
- },
- /**
- * Gets the radii of the ellipsoid raise to the fourth power.
- * @memberof Ellipsoid.prototype
- * @type {Cartesian3}
- * @readonly
- */
- radiiToTheFourth: {
- get: function () {
- return this._radiiToTheFourth;
- },
- },
- /**
- * Gets one over the radii of the ellipsoid.
- * @memberof Ellipsoid.prototype
- * @type {Cartesian3}
- * @readonly
- */
- oneOverRadii: {
- get: function () {
- return this._oneOverRadii;
- },
- },
- /**
- * Gets one over the squared radii of the ellipsoid.
- * @memberof Ellipsoid.prototype
- * @type {Cartesian3}
- * @readonly
- */
- oneOverRadiiSquared: {
- get: function () {
- return this._oneOverRadiiSquared;
- },
- },
- /**
- * Gets the minimum radius of the ellipsoid.
- * @memberof Ellipsoid.prototype
- * @type {number}
- * @readonly
- */
- minimumRadius: {
- get: function () {
- return this._minimumRadius;
- },
- },
- /**
- * Gets the maximum radius of the ellipsoid.
- * @memberof Ellipsoid.prototype
- * @type {number}
- * @readonly
- */
- maximumRadius: {
- get: function () {
- return this._maximumRadius;
- },
- },
- });
- /**
- * Duplicates an Ellipsoid instance.
- *
- * @param {Ellipsoid} ellipsoid The ellipsoid to duplicate.
- * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
- * instance should be created.
- * @returns {Ellipsoid} The cloned Ellipsoid. (Returns undefined if ellipsoid is undefined)
- */
- Ellipsoid.clone = function (ellipsoid, result) {
- if (!defaultValue.defined(ellipsoid)) {
- return undefined;
- }
- const radii = ellipsoid._radii;
- if (!defaultValue.defined(result)) {
- return new Ellipsoid(radii.x, radii.y, radii.z);
- }
- Cartesian3.clone(radii, result._radii);
- Cartesian3.clone(ellipsoid._radiiSquared, result._radiiSquared);
- Cartesian3.clone(ellipsoid._radiiToTheFourth, result._radiiToTheFourth);
- Cartesian3.clone(ellipsoid._oneOverRadii, result._oneOverRadii);
- Cartesian3.clone(ellipsoid._oneOverRadiiSquared, result._oneOverRadiiSquared);
- result._minimumRadius = ellipsoid._minimumRadius;
- result._maximumRadius = ellipsoid._maximumRadius;
- result._centerToleranceSquared = ellipsoid._centerToleranceSquared;
- return result;
- };
- /**
- * Computes an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.
- *
- * @param {Cartesian3} [cartesian=Cartesian3.ZERO] The ellipsoid's radius in the x, y, and z directions.
- * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
- * instance should be created.
- * @returns {Ellipsoid} A new Ellipsoid instance.
- *
- * @exception {DeveloperError} All radii components must be greater than or equal to zero.
- *
- * @see Ellipsoid.WGS84
- * @see Ellipsoid.UNIT_SPHERE
- */
- Ellipsoid.fromCartesian3 = function (cartesian, result) {
- if (!defaultValue.defined(result)) {
- result = new Ellipsoid();
- }
- if (!defaultValue.defined(cartesian)) {
- return result;
- }
- initialize(result, cartesian.x, cartesian.y, cartesian.z);
- return result;
- };
- /**
- * An Ellipsoid instance initialized to the WGS84 standard.
- *
- * @type {Ellipsoid}
- * @constant
- */
- Ellipsoid.WGS84 = Object.freeze(
- new Ellipsoid(6378137.0, 6378137.0, 6356752.3142451793)
- );
- /**
- * An Ellipsoid instance initialized to radii of (1.0, 1.0, 1.0).
- *
- * @type {Ellipsoid}
- * @constant
- */
- Ellipsoid.UNIT_SPHERE = Object.freeze(new Ellipsoid(1.0, 1.0, 1.0));
- /**
- * An Ellipsoid instance initialized to a sphere with the lunar radius.
- *
- * @type {Ellipsoid}
- * @constant
- */
- Ellipsoid.MOON = Object.freeze(
- new Ellipsoid(
- Math$1.CesiumMath.LUNAR_RADIUS,
- Math$1.CesiumMath.LUNAR_RADIUS,
- Math$1.CesiumMath.LUNAR_RADIUS
- )
- );
- /**
- * Duplicates an Ellipsoid instance.
- *
- * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
- * instance should be created.
- * @returns {Ellipsoid} The cloned Ellipsoid.
- */
- Ellipsoid.prototype.clone = function (result) {
- return Ellipsoid.clone(this, result);
- };
- /**
- * The number of elements used to pack the object into an array.
- * @type {number}
- */
- Ellipsoid.packedLength = Cartesian3.packedLength;
- /**
- * Stores the provided instance into the provided array.
- *
- * @param {Ellipsoid} value The value to pack.
- * @param {number[]} array The array to pack into.
- * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
- *
- * @returns {number[]} The array that was packed into
- */
- Ellipsoid.pack = function (value, array, startingIndex) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("value", value);
- Check.Check.defined("array", array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- Cartesian3.pack(value._radii, array, startingIndex);
- return array;
- };
- /**
- * Retrieves an instance from a packed array.
- *
- * @param {number[]} array The packed array.
- * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
- * @param {Ellipsoid} [result] The object into which to store the result.
- * @returns {Ellipsoid} The modified result parameter or a new Ellipsoid instance if one was not provided.
- */
- Ellipsoid.unpack = function (array, startingIndex, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("array", array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- const radii = Cartesian3.unpack(array, startingIndex);
- return Ellipsoid.fromCartesian3(radii, result);
- };
- /**
- * Computes the unit vector directed from the center of this ellipsoid toward the provided Cartesian position.
- * @function
- *
- * @param {Cartesian3} cartesian The Cartesian for which to to determine the geocentric normal.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
- */
- Ellipsoid.prototype.geocentricSurfaceNormal = Cartesian3.normalize;
- /**
- * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
- *
- * @param {Cartographic} cartographic The cartographic position for which to to determine the geodetic normal.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
- */
- Ellipsoid.prototype.geodeticSurfaceNormalCartographic = function (
- cartographic,
- result
- ) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartographic", cartographic);
- //>>includeEnd('debug');
- const longitude = cartographic.longitude;
- const latitude = cartographic.latitude;
- const cosLatitude = Math.cos(latitude);
- const x = cosLatitude * Math.cos(longitude);
- const y = cosLatitude * Math.sin(longitude);
- const z = Math.sin(latitude);
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- result.x = x;
- result.y = y;
- result.z = z;
- return Cartesian3.normalize(result, result);
- };
- /**
- * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
- *
- * @param {Cartesian3} cartesian The Cartesian position for which to to determine the surface normal.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided, or undefined if a normal cannot be found.
- */
- Ellipsoid.prototype.geodeticSurfaceNormal = function (cartesian, result) {
- if (
- Cartesian3.equalsEpsilon(cartesian, Cartesian3.ZERO, Math$1.CesiumMath.EPSILON14)
- ) {
- return undefined;
- }
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- result = Cartesian3.multiplyComponents(
- cartesian,
- this._oneOverRadiiSquared,
- result
- );
- return Cartesian3.normalize(result, result);
- };
- const cartographicToCartesianNormal = new Cartesian3();
- const cartographicToCartesianK = new Cartesian3();
- /**
- * Converts the provided cartographic to Cartesian representation.
- *
- * @param {Cartographic} cartographic The cartographic position.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
- *
- * @example
- * //Create a Cartographic and determine it's Cartesian representation on a WGS84 ellipsoid.
- * const position = new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 5000);
- * const cartesianPosition = Cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
- */
- Ellipsoid.prototype.cartographicToCartesian = function (cartographic, result) {
- //`cartographic is required` is thrown from geodeticSurfaceNormalCartographic.
- const n = cartographicToCartesianNormal;
- const k = cartographicToCartesianK;
- this.geodeticSurfaceNormalCartographic(cartographic, n);
- Cartesian3.multiplyComponents(this._radiiSquared, n, k);
- const gamma = Math.sqrt(Cartesian3.dot(n, k));
- Cartesian3.divideByScalar(k, gamma, k);
- Cartesian3.multiplyByScalar(n, cartographic.height, n);
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- return Cartesian3.add(k, n, result);
- };
- /**
- * Converts the provided array of cartographics to an array of Cartesians.
- *
- * @param {Cartographic[]} cartographics An array of cartographic positions.
- * @param {Cartesian3[]} [result] The object onto which to store the result.
- * @returns {Cartesian3[]} The modified result parameter or a new Array instance if none was provided.
- *
- * @example
- * //Convert an array of Cartographics and determine their Cartesian representation on a WGS84 ellipsoid.
- * const positions = [new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 0),
- * new Cesium.Cartographic(Cesium.Math.toRadians(21.321), Cesium.Math.toRadians(78.123), 100),
- * new Cesium.Cartographic(Cesium.Math.toRadians(21.645), Cesium.Math.toRadians(78.456), 250)];
- * const cartesianPositions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(positions);
- */
- Ellipsoid.prototype.cartographicArrayToCartesianArray = function (
- cartographics,
- result
- ) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("cartographics", cartographics);
- //>>includeEnd('debug')
- const length = cartographics.length;
- if (!defaultValue.defined(result)) {
- result = new Array(length);
- } else {
- result.length = length;
- }
- for (let i = 0; i < length; i++) {
- result[i] = this.cartographicToCartesian(cartographics[i], result[i]);
- }
- return result;
- };
- const cartesianToCartographicN = new Cartesian3();
- const cartesianToCartographicP = new Cartesian3();
- const cartesianToCartographicH = new Cartesian3();
- /**
- * Converts the provided cartesian to cartographic representation.
- * The cartesian is undefined at the center of the ellipsoid.
- *
- * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.
- * @param {Cartographic} [result] The object onto which to store the result.
- * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
- *
- * @example
- * //Create a Cartesian and determine it's Cartographic representation on a WGS84 ellipsoid.
- * const position = new Cesium.Cartesian3(17832.12, 83234.52, 952313.73);
- * const cartographicPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
- */
- Ellipsoid.prototype.cartesianToCartographic = function (cartesian, result) {
- //`cartesian is required.` is thrown from scaleToGeodeticSurface
- const p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
- if (!defaultValue.defined(p)) {
- return undefined;
- }
- const n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);
- const h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH);
- const longitude = Math.atan2(n.y, n.x);
- const latitude = Math.asin(n.z);
- const height =
- Math$1.CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);
- if (!defaultValue.defined(result)) {
- return new Cartographic(longitude, latitude, height);
- }
- result.longitude = longitude;
- result.latitude = latitude;
- result.height = height;
- return result;
- };
- /**
- * Converts the provided array of cartesians to an array of cartographics.
- *
- * @param {Cartesian3[]} cartesians An array of Cartesian positions.
- * @param {Cartographic[]} [result] The object onto which to store the result.
- * @returns {Cartographic[]} The modified result parameter or a new Array instance if none was provided.
- *
- * @example
- * //Create an array of Cartesians and determine their Cartographic representation on a WGS84 ellipsoid.
- * const positions = [new Cesium.Cartesian3(17832.12, 83234.52, 952313.73),
- * new Cesium.Cartesian3(17832.13, 83234.53, 952313.73),
- * new Cesium.Cartesian3(17832.14, 83234.54, 952313.73)]
- * const cartographicPositions = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(positions);
- */
- Ellipsoid.prototype.cartesianArrayToCartographicArray = function (
- cartesians,
- result
- ) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("cartesians", cartesians);
- //>>includeEnd('debug');
- const length = cartesians.length;
- if (!defaultValue.defined(result)) {
- result = new Array(length);
- } else {
- result.length = length;
- }
- for (let i = 0; i < length; ++i) {
- result[i] = this.cartesianToCartographic(cartesians[i], result[i]);
- }
- return result;
- };
- /**
- * Scales the provided Cartesian position along the geodetic surface normal
- * so that it is on the surface of this ellipsoid. If the position is
- * at the center of the ellipsoid, this function returns undefined.
- *
- * @param {Cartesian3} cartesian The Cartesian position to scale.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.
- */
- Ellipsoid.prototype.scaleToGeodeticSurface = function (cartesian, result) {
- return scaleToGeodeticSurface(
- cartesian,
- this._oneOverRadii,
- this._oneOverRadiiSquared,
- this._centerToleranceSquared,
- result
- );
- };
- /**
- * Scales the provided Cartesian position along the geocentric surface normal
- * so that it is on the surface of this ellipsoid.
- *
- * @param {Cartesian3} cartesian The Cartesian position to scale.
- * @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
- */
- Ellipsoid.prototype.scaleToGeocentricSurface = function (cartesian, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("cartesian", cartesian);
- //>>includeEnd('debug');
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- const positionX = cartesian.x;
- const positionY = cartesian.y;
- const positionZ = cartesian.z;
- const oneOverRadiiSquared = this._oneOverRadiiSquared;
- const beta =
- 1.0 /
- Math.sqrt(
- positionX * positionX * oneOverRadiiSquared.x +
- positionY * positionY * oneOverRadiiSquared.y +
- positionZ * positionZ * oneOverRadiiSquared.z
- );
- return Cartesian3.multiplyByScalar(cartesian, beta, result);
- };
- /**
- * Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
- * its components by the result of {@link Ellipsoid#oneOverRadii}.
- *
- * @param {Cartesian3} position The position to transform.
- * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and
- * return a new instance.
- * @returns {Cartesian3} The position expressed in the scaled space. The returned instance is the
- * one passed as the result parameter if it is not undefined, or a new instance of it is.
- */
- Ellipsoid.prototype.transformPositionToScaledSpace = function (
- position,
- result
- ) {
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- return Cartesian3.multiplyComponents(position, this._oneOverRadii, result);
- };
- /**
- * Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
- * its components by the result of {@link Ellipsoid#radii}.
- *
- * @param {Cartesian3} position The position to transform.
- * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and
- * return a new instance.
- * @returns {Cartesian3} The position expressed in the unscaled space. The returned instance is the
- * one passed as the result parameter if it is not undefined, or a new instance of it is.
- */
- Ellipsoid.prototype.transformPositionFromScaledSpace = function (
- position,
- result
- ) {
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- return Cartesian3.multiplyComponents(position, this._radii, result);
- };
- /**
- * Compares this Ellipsoid against the provided Ellipsoid componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {Ellipsoid} [right] The other Ellipsoid.
- * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
- */
- Ellipsoid.prototype.equals = function (right) {
- return (
- this === right ||
- (defaultValue.defined(right) && Cartesian3.equals(this._radii, right._radii))
- );
- };
- /**
- * Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.
- *
- * @returns {string} A string representing this ellipsoid in the format '(radii.x, radii.y, radii.z)'.
- */
- Ellipsoid.prototype.toString = function () {
- return this._radii.toString();
- };
- /**
- * Computes a point which is the intersection of the surface normal with the z-axis.
- *
- * @param {Cartesian3} position the position. must be on the surface of the ellipsoid.
- * @param {number} [buffer = 0.0] A buffer to subtract from the ellipsoid size when checking if the point is inside the ellipsoid.
- * In earth case, with common earth datums, there is no need for this buffer since the intersection point is always (relatively) very close to the center.
- * In WGS84 datum, intersection point is at max z = +-42841.31151331382 (0.673% of z-axis).
- * Intersection point could be outside the ellipsoid if the ratio of MajorAxis / AxisOfRotation is bigger than the square root of 2
- * @param {Cartesian3} [result] The cartesian to which to copy the result, or undefined to create and
- * return a new instance.
- * @returns {Cartesian3 | undefined} the intersection point if it's inside the ellipsoid, undefined otherwise
- *
- * @exception {DeveloperError} position is required.
- * @exception {DeveloperError} Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y).
- * @exception {DeveloperError} Ellipsoid.radii.z must be greater than 0.
- */
- Ellipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function (
- position,
- buffer,
- result
- ) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("position", position);
- if (
- !Math$1.CesiumMath.equalsEpsilon(
- this._radii.x,
- this._radii.y,
- Math$1.CesiumMath.EPSILON15
- )
- ) {
- throw new Check.DeveloperError(
- "Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)"
- );
- }
- Check.Check.typeOf.number.greaterThan("Ellipsoid.radii.z", this._radii.z, 0);
- //>>includeEnd('debug');
- buffer = defaultValue.defaultValue(buffer, 0.0);
- const squaredXOverSquaredZ = this._squaredXOverSquaredZ;
- if (!defaultValue.defined(result)) {
- result = new Cartesian3();
- }
- result.x = 0.0;
- result.y = 0.0;
- result.z = position.z * (1 - squaredXOverSquaredZ);
- if (Math.abs(result.z) >= this._radii.z - buffer) {
- return undefined;
- }
- return result;
- };
- const abscissas = [
- 0.14887433898163,
- 0.43339539412925,
- 0.67940956829902,
- 0.86506336668898,
- 0.97390652851717,
- 0.0,
- ];
- const weights = [
- 0.29552422471475,
- 0.26926671930999,
- 0.21908636251598,
- 0.14945134915058,
- 0.066671344308684,
- 0.0,
- ];
- /**
- * Compute the 10th order Gauss-Legendre Quadrature of the given definite integral.
- *
- * @param {number} a The lower bound for the integration.
- * @param {number} b The upper bound for the integration.
- * @param {Ellipsoid~RealValuedScalarFunction} func The function to integrate.
- * @returns {number} The value of the integral of the given function over the given domain.
- *
- * @private
- */
- function gaussLegendreQuadrature(a, b, func) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("a", a);
- Check.Check.typeOf.number("b", b);
- Check.Check.typeOf.func("func", func);
- //>>includeEnd('debug');
- // The range is half of the normal range since the five weights add to one (ten weights add to two).
- // The values of the abscissas are multiplied by two to account for this.
- const xMean = 0.5 * (b + a);
- const xRange = 0.5 * (b - a);
- let sum = 0.0;
- for (let i = 0; i < 5; i++) {
- const dx = xRange * abscissas[i];
- sum += weights[i] * (func(xMean + dx) + func(xMean - dx));
- }
- // Scale the sum to the range of x.
- sum *= xRange;
- return sum;
- }
- /**
- * A real valued scalar function.
- * @callback Ellipsoid~RealValuedScalarFunction
- *
- * @param {number} x The value used to evaluate the function.
- * @returns {number} The value of the function at x.
- *
- * @private
- */
- /**
- * Computes an approximation of the surface area of a rectangle on the surface of an ellipsoid using
- * Gauss-Legendre 10th order quadrature.
- *
- * @param {Rectangle} rectangle The rectangle used for computing the surface area.
- * @returns {number} The approximate area of the rectangle on the surface of this ellipsoid.
- */
- Ellipsoid.prototype.surfaceArea = function (rectangle) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("rectangle", rectangle);
- //>>includeEnd('debug');
- const minLongitude = rectangle.west;
- let maxLongitude = rectangle.east;
- const minLatitude = rectangle.south;
- const maxLatitude = rectangle.north;
- while (maxLongitude < minLongitude) {
- maxLongitude += Math$1.CesiumMath.TWO_PI;
- }
- const radiiSquared = this._radiiSquared;
- const a2 = radiiSquared.x;
- const b2 = radiiSquared.y;
- const c2 = radiiSquared.z;
- const a2b2 = a2 * b2;
- return gaussLegendreQuadrature(minLatitude, maxLatitude, function (lat) {
- // phi represents the angle measured from the north pole
- // sin(phi) = sin(pi / 2 - lat) = cos(lat), cos(phi) is similar
- const sinPhi = Math.cos(lat);
- const cosPhi = Math.sin(lat);
- return (
- Math.cos(lat) *
- gaussLegendreQuadrature(minLongitude, maxLongitude, function (lon) {
- const cosTheta = Math.cos(lon);
- const sinTheta = Math.sin(lon);
- return Math.sqrt(
- a2b2 * cosPhi * cosPhi +
- c2 *
- (b2 * cosTheta * cosTheta + a2 * sinTheta * sinTheta) *
- sinPhi *
- sinPhi
- );
- })
- );
- });
- };
- /**
- * A 3x3 matrix, indexable as a column-major order array.
- * Constructor parameters are in row-major order for code readability.
- * @alias Matrix3
- * @constructor
- * @implements {ArrayLike<number>}
- *
- * @param {number} [column0Row0=0.0] The value for column 0, row 0.
- * @param {number} [column1Row0=0.0] The value for column 1, row 0.
- * @param {number} [column2Row0=0.0] The value for column 2, row 0.
- * @param {number} [column0Row1=0.0] The value for column 0, row 1.
- * @param {number} [column1Row1=0.0] The value for column 1, row 1.
- * @param {number} [column2Row1=0.0] The value for column 2, row 1.
- * @param {number} [column0Row2=0.0] The value for column 0, row 2.
- * @param {number} [column1Row2=0.0] The value for column 1, row 2.
- * @param {number} [column2Row2=0.0] The value for column 2, row 2.
- *
- * @see Matrix3.fromArray
- * @see Matrix3.fromColumnMajorArray
- * @see Matrix3.fromRowMajorArray
- * @see Matrix3.fromQuaternion
- * @see Matrix3.fromHeadingPitchRoll
- * @see Matrix3.fromScale
- * @see Matrix3.fromUniformScale
- * @see Matrix3.fromCrossProduct
- * @see Matrix3.fromRotationX
- * @see Matrix3.fromRotationY
- * @see Matrix3.fromRotationZ
- * @see Matrix2
- * @see Matrix4
- */
- function Matrix3(
- column0Row0,
- column1Row0,
- column2Row0,
- column0Row1,
- column1Row1,
- column2Row1,
- column0Row2,
- column1Row2,
- column2Row2
- ) {
- this[0] = defaultValue.defaultValue(column0Row0, 0.0);
- this[1] = defaultValue.defaultValue(column0Row1, 0.0);
- this[2] = defaultValue.defaultValue(column0Row2, 0.0);
- this[3] = defaultValue.defaultValue(column1Row0, 0.0);
- this[4] = defaultValue.defaultValue(column1Row1, 0.0);
- this[5] = defaultValue.defaultValue(column1Row2, 0.0);
- this[6] = defaultValue.defaultValue(column2Row0, 0.0);
- this[7] = defaultValue.defaultValue(column2Row1, 0.0);
- this[8] = defaultValue.defaultValue(column2Row2, 0.0);
- }
- /**
- * The number of elements used to pack the object into an array.
- * @type {number}
- */
- Matrix3.packedLength = 9;
- /**
- * Stores the provided instance into the provided array.
- *
- * @param {Matrix3} value The value to pack.
- * @param {number[]} array The array to pack into.
- * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
- *
- * @returns {number[]} The array that was packed into
- */
- Matrix3.pack = function (value, array, startingIndex) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("value", value);
- Check.Check.defined("array", array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- array[startingIndex++] = value[0];
- array[startingIndex++] = value[1];
- array[startingIndex++] = value[2];
- array[startingIndex++] = value[3];
- array[startingIndex++] = value[4];
- array[startingIndex++] = value[5];
- array[startingIndex++] = value[6];
- array[startingIndex++] = value[7];
- array[startingIndex++] = value[8];
- return array;
- };
- /**
- * Retrieves an instance from a packed array.
- *
- * @param {number[]} array The packed array.
- * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
- * @param {Matrix3} [result] The object into which to store the result.
- * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
- */
- Matrix3.unpack = function (array, startingIndex, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("array", array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- if (!defaultValue.defined(result)) {
- result = new Matrix3();
- }
- result[0] = array[startingIndex++];
- result[1] = array[startingIndex++];
- result[2] = array[startingIndex++];
- result[3] = array[startingIndex++];
- result[4] = array[startingIndex++];
- result[5] = array[startingIndex++];
- result[6] = array[startingIndex++];
- result[7] = array[startingIndex++];
- result[8] = array[startingIndex++];
- return result;
- };
- /**
- * Flattens an array of Matrix3s into an array of components. The components
- * are stored in column-major order.
- *
- * @param {Matrix3[]} array The array of matrices to pack.
- * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 9 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 9) elements.
- * @returns {number[]} The packed array.
- */
- Matrix3.packArray = function (array, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("array", array);
- //>>includeEnd('debug');
- const length = array.length;
- const resultLength = length * 9;
- if (!defaultValue.defined(result)) {
- result = new Array(resultLength);
- } else if (!Array.isArray(result) && result.length !== resultLength) {
- //>>includeStart('debug', pragmas.debug);
- throw new Check.DeveloperError(
- "If result is a typed array, it must have exactly array.length * 9 elements"
- );
- //>>includeEnd('debug');
- } else if (result.length !== resultLength) {
- result.length = resultLength;
- }
- for (let i = 0; i < length; ++i) {
- Matrix3.pack(array[i], result, i * 9);
- }
- return result;
- };
- /**
- * Unpacks an array of column-major matrix components into an array of Matrix3s.
- *
- * @param {number[]} array The array of components to unpack.
- * @param {Matrix3[]} [result] The array onto which to store the result.
- * @returns {Matrix3[]} The unpacked array.
- */
- Matrix3.unpackArray = function (array, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("array", array);
- Check.Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 9);
- if (array.length % 9 !== 0) {
- throw new Check.DeveloperError("array length must be a multiple of 9.");
- }
- //>>includeEnd('debug');
- const length = array.length;
- if (!defaultValue.defined(result)) {
- result = new Array(length / 9);
- } else {
- result.length = length / 9;
- }
- for (let i = 0; i < length; i += 9) {
- const index = i / 9;
- result[index] = Matrix3.unpack(array, i, result[index]);
- }
- return result;
- };
- /**
- * Duplicates a Matrix3 instance.
- *
- * @param {Matrix3} matrix The matrix to duplicate.
- * @param {Matrix3} [result] The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined)
- */
- Matrix3.clone = function (matrix, result) {
- if (!defaultValue.defined(matrix)) {
- return undefined;
- }
- if (!defaultValue.defined(result)) {
- return new Matrix3(
- matrix[0],
- matrix[3],
- matrix[6],
- matrix[1],
- matrix[4],
- matrix[7],
- matrix[2],
- matrix[5],
- matrix[8]
- );
- }
- result[0] = matrix[0];
- result[1] = matrix[1];
- result[2] = matrix[2];
- result[3] = matrix[3];
- result[4] = matrix[4];
- result[5] = matrix[5];
- result[6] = matrix[6];
- result[7] = matrix[7];
- result[8] = matrix[8];
- return result;
- };
- /**
- * Creates a Matrix3 from 9 consecutive elements in an array.
- *
- * @function
- * @param {number[]} array The array whose 9 consecutive elements correspond to the positions of the matrix. Assumes column-major order.
- * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.
- * @param {Matrix3} [result] The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
- *
- * @example
- * // Create the Matrix3:
- * // [1.0, 2.0, 3.0]
- * // [1.0, 2.0, 3.0]
- * // [1.0, 2.0, 3.0]
- *
- * const v = [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
- * const m = Cesium.Matrix3.fromArray(v);
- *
- * // Create same Matrix3 with using an offset into an array
- * const v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
- * const m2 = Cesium.Matrix3.fromArray(v2, 2);
- */
- Matrix3.fromArray = Matrix3.unpack;
- /**
- * Creates a Matrix3 instance from a column-major order array.
- *
- * @param {number[]} values The column-major order array.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
- */
- Matrix3.fromColumnMajorArray = function (values, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("values", values);
- //>>includeEnd('debug');
- return Matrix3.clone(values, result);
- };
- /**
- * Creates a Matrix3 instance from a row-major order array.
- * The resulting matrix will be in column-major order.
- *
- * @param {number[]} values The row-major order array.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
- */
- Matrix3.fromRowMajorArray = function (values, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined("values", values);
- //>>includeEnd('debug');
- if (!defaultValue.defined(result)) {
- return new Matrix3(
- values[0],
- values[1],
- values[2],
- values[3],
- values[4],
- values[5],
- values[6],
- values[7],
- values[8]
- );
- }
- result[0] = values[0];
- result[1] = values[3];
- result[2] = values[6];
- result[3] = values[1];
- result[4] = values[4];
- result[5] = values[7];
- result[6] = values[2];
- result[7] = values[5];
- result[8] = values[8];
- return result;
- };
- /**
- * Computes a 3x3 rotation matrix from the provided quaternion.
- *
- * @param {Quaternion} quaternion the quaternion to use.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The 3x3 rotation matrix from this quaternion.
- */
- Matrix3.fromQuaternion = function (quaternion, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("quaternion", quaternion);
- //>>includeEnd('debug');
- const x2 = quaternion.x * quaternion.x;
- const xy = quaternion.x * quaternion.y;
- const xz = quaternion.x * quaternion.z;
- const xw = quaternion.x * quaternion.w;
- const y2 = quaternion.y * quaternion.y;
- const yz = quaternion.y * quaternion.z;
- const yw = quaternion.y * quaternion.w;
- const z2 = quaternion.z * quaternion.z;
- const zw = quaternion.z * quaternion.w;
- const w2 = quaternion.w * quaternion.w;
- const m00 = x2 - y2 - z2 + w2;
- const m01 = 2.0 * (xy - zw);
- const m02 = 2.0 * (xz + yw);
- const m10 = 2.0 * (xy + zw);
- const m11 = -x2 + y2 - z2 + w2;
- const m12 = 2.0 * (yz - xw);
- const m20 = 2.0 * (xz - yw);
- const m21 = 2.0 * (yz + xw);
- const m22 = -x2 - y2 + z2 + w2;
- if (!defaultValue.defined(result)) {
- return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
- }
- result[0] = m00;
- result[1] = m10;
- result[2] = m20;
- result[3] = m01;
- result[4] = m11;
- result[5] = m21;
- result[6] = m02;
- result[7] = m12;
- result[8] = m22;
- return result;
- };
- /**
- * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
- *
- * @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll.
- */
- Matrix3.fromHeadingPitchRoll = function (headingPitchRoll, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("headingPitchRoll", headingPitchRoll);
- //>>includeEnd('debug');
- const cosTheta = Math.cos(-headingPitchRoll.pitch);
- const cosPsi = Math.cos(-headingPitchRoll.heading);
- const cosPhi = Math.cos(headingPitchRoll.roll);
- const sinTheta = Math.sin(-headingPitchRoll.pitch);
- const sinPsi = Math.sin(-headingPitchRoll.heading);
- const sinPhi = Math.sin(headingPitchRoll.roll);
- const m00 = cosTheta * cosPsi;
- const m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;
- const m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi;
- const m10 = cosTheta * sinPsi;
- const m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi;
- const m12 = -sinPhi * cosPsi + cosPhi * sinTheta * sinPsi;
- const m20 = -sinTheta;
- const m21 = sinPhi * cosTheta;
- const m22 = cosPhi * cosTheta;
- if (!defaultValue.defined(result)) {
- return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
- }
- result[0] = m00;
- result[1] = m10;
- result[2] = m20;
- result[3] = m01;
- result[4] = m11;
- result[5] = m21;
- result[6] = m02;
- result[7] = m12;
- result[8] = m22;
- return result;
- };
- /**
- * Computes a Matrix3 instance representing a non-uniform scale.
- *
- * @param {Cartesian3} scale The x, y, and z scale factors.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
- *
- * @example
- * // Creates
- * // [7.0, 0.0, 0.0]
- * // [0.0, 8.0, 0.0]
- * // [0.0, 0.0, 9.0]
- * const m = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
- */
- Matrix3.fromScale = function (scale, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("scale", scale);
- //>>includeEnd('debug');
- if (!defaultValue.defined(result)) {
- return new Matrix3(scale.x, 0.0, 0.0, 0.0, scale.y, 0.0, 0.0, 0.0, scale.z);
- }
- result[0] = scale.x;
- result[1] = 0.0;
- result[2] = 0.0;
- result[3] = 0.0;
- result[4] = scale.y;
- result[5] = 0.0;
- result[6] = 0.0;
- result[7] = 0.0;
- result[8] = scale.z;
- return result;
- };
- /**
- * Computes a Matrix3 instance representing a uniform scale.
- *
- * @param {number} scale The uniform scale factor.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
- *
- * @example
- * // Creates
- * // [2.0, 0.0, 0.0]
- * // [0.0, 2.0, 0.0]
- * // [0.0, 0.0, 2.0]
- * const m = Cesium.Matrix3.fromUniformScale(2.0);
- */
- Matrix3.fromUniformScale = function (scale, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("scale", scale);
- //>>includeEnd('debug');
- if (!defaultValue.defined(result)) {
- return new Matrix3(scale, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, scale);
- }
- result[0] = scale;
- result[1] = 0.0;
- result[2] = 0.0;
- result[3] = 0.0;
- result[4] = scale;
- result[5] = 0.0;
- result[6] = 0.0;
- result[7] = 0.0;
- result[8] = scale;
- return result;
- };
- /**
- * Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector.
- *
- * @param {Cartesian3} vector the vector on the left hand side of the cross product operation.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
- *
- * @example
- * // Creates
- * // [0.0, -9.0, 8.0]
- * // [9.0, 0.0, -7.0]
- * // [-8.0, 7.0, 0.0]
- * const m = Cesium.Matrix3.fromCrossProduct(new Cesium.Cartesian3(7.0, 8.0, 9.0));
- */
- Matrix3.fromCrossProduct = function (vector, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("vector", vector);
- //>>includeEnd('debug');
- if (!defaultValue.defined(result)) {
- return new Matrix3(
- 0.0,
- -vector.z,
- vector.y,
- vector.z,
- 0.0,
- -vector.x,
- -vector.y,
- vector.x,
- 0.0
- );
- }
- result[0] = 0.0;
- result[1] = vector.z;
- result[2] = -vector.y;
- result[3] = -vector.z;
- result[4] = 0.0;
- result[5] = vector.x;
- result[6] = vector.y;
- result[7] = -vector.x;
- result[8] = 0.0;
- return result;
- };
- /**
- * Creates a rotation matrix around the x-axis.
- *
- * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
- *
- * @example
- * // Rotate a point 45 degrees counterclockwise around the x-axis.
- * const p = new Cesium.Cartesian3(5, 6, 7);
- * const m = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(45.0));
- * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
- */
- Matrix3.fromRotationX = function (angle, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("angle", angle);
- //>>includeEnd('debug');
- const cosAngle = Math.cos(angle);
- const sinAngle = Math.sin(angle);
- if (!defaultValue.defined(result)) {
- return new Matrix3(
- 1.0,
- 0.0,
- 0.0,
- 0.0,
- cosAngle,
- -sinAngle,
- 0.0,
- sinAngle,
- cosAngle
- );
- }
- result[0] = 1.0;
- result[1] = 0.0;
- result[2] = 0.0;
- result[3] = 0.0;
- result[4] = cosAngle;
- result[5] = sinAngle;
- result[6] = 0.0;
- result[7] = -sinAngle;
- result[8] = cosAngle;
- return result;
- };
- /**
- * Creates a rotation matrix around the y-axis.
- *
- * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
- *
- * @example
- * // Rotate a point 45 degrees counterclockwise around the y-axis.
- * const p = new Cesium.Cartesian3(5, 6, 7);
- * const m = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(45.0));
- * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
- */
- Matrix3.fromRotationY = function (angle, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("angle", angle);
- //>>includeEnd('debug');
- const cosAngle = Math.cos(angle);
- const sinAngle = Math.sin(angle);
- if (!defaultValue.defined(result)) {
- return new Matrix3(
- cosAngle,
- 0.0,
- sinAngle,
- 0.0,
- 1.0,
- 0.0,
- -sinAngle,
- 0.0,
- cosAngle
- );
- }
- result[0] = cosAngle;
- result[1] = 0.0;
- result[2] = -sinAngle;
- result[3] = 0.0;
- result[4] = 1.0;
- result[5] = 0.0;
- result[6] = sinAngle;
- result[7] = 0.0;
- result[8] = cosAngle;
- return result;
- };
- /**
- * Creates a rotation matrix around the z-axis.
- *
- * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
- *
- * @example
- * // Rotate a point 45 degrees counterclockwise around the z-axis.
- * const p = new Cesium.Cartesian3(5, 6, 7);
- * const m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(45.0));
- * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
- */
- Matrix3.fromRotationZ = function (angle, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number("angle", angle);
- //>>includeEnd('debug');
- const cosAngle = Math.cos(angle);
- const sinAngle = Math.sin(angle);
- if (!defaultValue.defined(result)) {
- return new Matrix3(
- cosAngle,
- -sinAngle,
- 0.0,
- sinAngle,
- cosAngle,
- 0.0,
- 0.0,
- 0.0,
- 1.0
- );
- }
- result[0] = cosAngle;
- result[1] = sinAngle;
- result[2] = 0.0;
- result[3] = -sinAngle;
- result[4] = cosAngle;
- result[5] = 0.0;
- result[6] = 0.0;
- result[7] = 0.0;
- result[8] = 1.0;
- return result;
- };
- /**
- * Creates an Array from the provided Matrix3 instance.
- * The array will be in column-major order.
- *
- * @param {Matrix3} matrix The matrix to use..
- * @param {number[]} [result] The Array onto which to store the result.
- * @returns {number[]} The modified Array parameter or a new Array instance if one was not provided.
- */
- Matrix3.toArray = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- //>>includeEnd('debug');
- if (!defaultValue.defined(result)) {
- return [
- matrix[0],
- matrix[1],
- matrix[2],
- matrix[3],
- matrix[4],
- matrix[5],
- matrix[6],
- matrix[7],
- matrix[8],
- ];
- }
- result[0] = matrix[0];
- result[1] = matrix[1];
- result[2] = matrix[2];
- result[3] = matrix[3];
- result[4] = matrix[4];
- result[5] = matrix[5];
- result[6] = matrix[6];
- result[7] = matrix[7];
- result[8] = matrix[8];
- return result;
- };
- /**
- * Computes the array index of the element at the provided row and column.
- *
- * @param {number} column The zero-based index of the column.
- * @param {number} row The zero-based index of the row.
- * @returns {number} The index of the element at the provided row and column.
- *
- * @exception {DeveloperError} row must be 0, 1, or 2.
- * @exception {DeveloperError} column must be 0, 1, or 2.
- *
- * @example
- * const myMatrix = new Cesium.Matrix3();
- * const column1Row0Index = Cesium.Matrix3.getElementIndex(1, 0);
- * const column1Row0 = myMatrix[column1Row0Index]
- * myMatrix[column1Row0Index] = 10.0;
- */
- Matrix3.getElementIndex = function (column, row) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.number.greaterThanOrEquals("row", row, 0);
- Check.Check.typeOf.number.lessThanOrEquals("row", row, 2);
- Check.Check.typeOf.number.greaterThanOrEquals("column", column, 0);
- Check.Check.typeOf.number.lessThanOrEquals("column", column, 2);
- //>>includeEnd('debug');
- return column * 3 + row;
- };
- /**
- * Retrieves a copy of the matrix column at the provided index as a Cartesian3 instance.
- *
- * @param {Matrix3} matrix The matrix to use.
- * @param {number} index The zero-based index of the column to retrieve.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- *
- * @exception {DeveloperError} index must be 0, 1, or 2.
- */
- Matrix3.getColumn = function (matrix, index, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.number.greaterThanOrEquals("index", index, 0);
- Check.Check.typeOf.number.lessThanOrEquals("index", index, 2);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const startIndex = index * 3;
- const x = matrix[startIndex];
- const y = matrix[startIndex + 1];
- const z = matrix[startIndex + 2];
- result.x = x;
- result.y = y;
- result.z = z;
- return result;
- };
- /**
- * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian3 instance.
- *
- * @param {Matrix3} matrix The matrix to use.
- * @param {number} index The zero-based index of the column to set.
- * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified column.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- * @exception {DeveloperError} index must be 0, 1, or 2.
- */
- Matrix3.setColumn = function (matrix, index, cartesian, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.number.greaterThanOrEquals("index", index, 0);
- Check.Check.typeOf.number.lessThanOrEquals("index", index, 2);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result = Matrix3.clone(matrix, result);
- const startIndex = index * 3;
- result[startIndex] = cartesian.x;
- result[startIndex + 1] = cartesian.y;
- result[startIndex + 2] = cartesian.z;
- return result;
- };
- /**
- * Retrieves a copy of the matrix row at the provided index as a Cartesian3 instance.
- *
- * @param {Matrix3} matrix The matrix to use.
- * @param {number} index The zero-based index of the row to retrieve.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- *
- * @exception {DeveloperError} index must be 0, 1, or 2.
- */
- Matrix3.getRow = function (matrix, index, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.number.greaterThanOrEquals("index", index, 0);
- Check.Check.typeOf.number.lessThanOrEquals("index", index, 2);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const x = matrix[index];
- const y = matrix[index + 3];
- const z = matrix[index + 6];
- result.x = x;
- result.y = y;
- result.z = z;
- return result;
- };
- /**
- * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian3 instance.
- *
- * @param {Matrix3} matrix The matrix to use.
- * @param {number} index The zero-based index of the row to set.
- * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified row.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- * @exception {DeveloperError} index must be 0, 1, or 2.
- */
- Matrix3.setRow = function (matrix, index, cartesian, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.number.greaterThanOrEquals("index", index, 0);
- Check.Check.typeOf.number.lessThanOrEquals("index", index, 2);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result = Matrix3.clone(matrix, result);
- result[index] = cartesian.x;
- result[index + 3] = cartesian.y;
- result[index + 6] = cartesian.z;
- return result;
- };
- const scaleScratch1 = new Cartesian3();
- /**
- * Computes a new matrix that replaces the scale with the provided scale.
- * This assumes the matrix is an affine transformation.
- *
- * @param {Matrix3} matrix The matrix to use.
- * @param {Cartesian3} scale The scale that replaces the scale of the provided matrix.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- * @see Matrix3.setUniformScale
- * @see Matrix3.fromScale
- * @see Matrix3.fromUniformScale
- * @see Matrix3.multiplyByScale
- * @see Matrix3.multiplyByUniformScale
- * @see Matrix3.getScale
- */
- Matrix3.setScale = function (matrix, scale, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("scale", scale);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const existingScale = Matrix3.getScale(matrix, scaleScratch1);
- const scaleRatioX = scale.x / existingScale.x;
- const scaleRatioY = scale.y / existingScale.y;
- const scaleRatioZ = scale.z / existingScale.z;
- result[0] = matrix[0] * scaleRatioX;
- result[1] = matrix[1] * scaleRatioX;
- result[2] = matrix[2] * scaleRatioX;
- result[3] = matrix[3] * scaleRatioY;
- result[4] = matrix[4] * scaleRatioY;
- result[5] = matrix[5] * scaleRatioY;
- result[6] = matrix[6] * scaleRatioZ;
- result[7] = matrix[7] * scaleRatioZ;
- result[8] = matrix[8] * scaleRatioZ;
- return result;
- };
- const scaleScratch2 = new Cartesian3();
- /**
- * Computes a new matrix that replaces the scale with the provided uniform scale.
- * This assumes the matrix is an affine transformation.
- *
- * @param {Matrix3} matrix The matrix to use.
- * @param {number} scale The uniform scale that replaces the scale of the provided matrix.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- * @see Matrix3.setScale
- * @see Matrix3.fromScale
- * @see Matrix3.fromUniformScale
- * @see Matrix3.multiplyByScale
- * @see Matrix3.multiplyByUniformScale
- * @see Matrix3.getScale
- */
- Matrix3.setUniformScale = function (matrix, scale, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.number("scale", scale);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const existingScale = Matrix3.getScale(matrix, scaleScratch2);
- const scaleRatioX = scale / existingScale.x;
- const scaleRatioY = scale / existingScale.y;
- const scaleRatioZ = scale / existingScale.z;
- result[0] = matrix[0] * scaleRatioX;
- result[1] = matrix[1] * scaleRatioX;
- result[2] = matrix[2] * scaleRatioX;
- result[3] = matrix[3] * scaleRatioY;
- result[4] = matrix[4] * scaleRatioY;
- result[5] = matrix[5] * scaleRatioY;
- result[6] = matrix[6] * scaleRatioZ;
- result[7] = matrix[7] * scaleRatioZ;
- result[8] = matrix[8] * scaleRatioZ;
- return result;
- };
- const scratchColumn = new Cartesian3();
- /**
- * Extracts the non-uniform scale assuming the matrix is an affine transformation.
- *
- * @param {Matrix3} matrix The matrix.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- *
- * @see Matrix3.multiplyByScale
- * @see Matrix3.multiplyByUniformScale
- * @see Matrix3.fromScale
- * @see Matrix3.fromUniformScale
- * @see Matrix3.setScale
- * @see Matrix3.setUniformScale
- */
- Matrix3.getScale = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result.x = Cartesian3.magnitude(
- Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)
- );
- result.y = Cartesian3.magnitude(
- Cartesian3.fromElements(matrix[3], matrix[4], matrix[5], scratchColumn)
- );
- result.z = Cartesian3.magnitude(
- Cartesian3.fromElements(matrix[6], matrix[7], matrix[8], scratchColumn)
- );
- return result;
- };
- const scaleScratch3 = new Cartesian3();
- /**
- * Computes the maximum scale assuming the matrix is an affine transformation.
- * The maximum scale is the maximum length of the column vectors.
- *
- * @param {Matrix3} matrix The matrix.
- * @returns {number} The maximum scale.
- */
- Matrix3.getMaximumScale = function (matrix) {
- Matrix3.getScale(matrix, scaleScratch3);
- return Cartesian3.maximumComponent(scaleScratch3);
- };
- const scaleScratch4 = new Cartesian3();
- /**
- * Sets the rotation assuming the matrix is an affine transformation.
- *
- * @param {Matrix3} matrix The matrix.
- * @param {Matrix3} rotation The rotation matrix.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- * @see Matrix3.getRotation
- */
- Matrix3.setRotation = function (matrix, rotation, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const scale = Matrix3.getScale(matrix, scaleScratch4);
- result[0] = rotation[0] * scale.x;
- result[1] = rotation[1] * scale.x;
- result[2] = rotation[2] * scale.x;
- result[3] = rotation[3] * scale.y;
- result[4] = rotation[4] * scale.y;
- result[5] = rotation[5] * scale.y;
- result[6] = rotation[6] * scale.z;
- result[7] = rotation[7] * scale.z;
- result[8] = rotation[8] * scale.z;
- return result;
- };
- const scaleScratch5 = new Cartesian3();
- /**
- * Extracts the rotation matrix assuming the matrix is an affine transformation.
- *
- * @param {Matrix3} matrix The matrix.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- * @see Matrix3.setRotation
- */
- Matrix3.getRotation = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const scale = Matrix3.getScale(matrix, scaleScratch5);
- result[0] = matrix[0] / scale.x;
- result[1] = matrix[1] / scale.x;
- result[2] = matrix[2] / scale.x;
- result[3] = matrix[3] / scale.y;
- result[4] = matrix[4] / scale.y;
- result[5] = matrix[5] / scale.y;
- result[6] = matrix[6] / scale.z;
- result[7] = matrix[7] / scale.z;
- result[8] = matrix[8] / scale.z;
- return result;
- };
- /**
- * Computes the product of two matrices.
- *
- * @param {Matrix3} left The first matrix.
- * @param {Matrix3} right The second matrix.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- */
- Matrix3.multiply = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const column0Row0 =
- left[0] * right[0] + left[3] * right[1] + left[6] * right[2];
- const column0Row1 =
- left[1] * right[0] + left[4] * right[1] + left[7] * right[2];
- const column0Row2 =
- left[2] * right[0] + left[5] * right[1] + left[8] * right[2];
- const column1Row0 =
- left[0] * right[3] + left[3] * right[4] + left[6] * right[5];
- const column1Row1 =
- left[1] * right[3] + left[4] * right[4] + left[7] * right[5];
- const column1Row2 =
- left[2] * right[3] + left[5] * right[4] + left[8] * right[5];
- const column2Row0 =
- left[0] * right[6] + left[3] * right[7] + left[6] * right[8];
- const column2Row1 =
- left[1] * right[6] + left[4] * right[7] + left[7] * right[8];
- const column2Row2 =
- left[2] * right[6] + left[5] * right[7] + left[8] * right[8];
- result[0] = column0Row0;
- result[1] = column0Row1;
- result[2] = column0Row2;
- result[3] = column1Row0;
- result[4] = column1Row1;
- result[5] = column1Row2;
- result[6] = column2Row0;
- result[7] = column2Row1;
- result[8] = column2Row2;
- return result;
- };
- /**
- * Computes the sum of two matrices.
- *
- * @param {Matrix3} left The first matrix.
- * @param {Matrix3} right The second matrix.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- */
- Matrix3.add = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result[0] = left[0] + right[0];
- result[1] = left[1] + right[1];
- result[2] = left[2] + right[2];
- result[3] = left[3] + right[3];
- result[4] = left[4] + right[4];
- result[5] = left[5] + right[5];
- result[6] = left[6] + right[6];
- result[7] = left[7] + right[7];
- result[8] = left[8] + right[8];
- return result;
- };
- /**
- * Computes the difference of two matrices.
- *
- * @param {Matrix3} left The first matrix.
- * @param {Matrix3} right The second matrix.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- */
- Matrix3.subtract = function (left, right, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("left", left);
- Check.Check.typeOf.object("right", right);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result[0] = left[0] - right[0];
- result[1] = left[1] - right[1];
- result[2] = left[2] - right[2];
- result[3] = left[3] - right[3];
- result[4] = left[4] - right[4];
- result[5] = left[5] - right[5];
- result[6] = left[6] - right[6];
- result[7] = left[7] - right[7];
- result[8] = left[8] - right[8];
- return result;
- };
- /**
- * Computes the product of a matrix and a column vector.
- *
- * @param {Matrix3} matrix The matrix.
- * @param {Cartesian3} cartesian The column.
- * @param {Cartesian3} result The object onto which to store the result.
- * @returns {Cartesian3} The modified result parameter.
- */
- Matrix3.multiplyByVector = function (matrix, cartesian, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("cartesian", cartesian);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const vX = cartesian.x;
- const vY = cartesian.y;
- const vZ = cartesian.z;
- const x = matrix[0] * vX + matrix[3] * vY + matrix[6] * vZ;
- const y = matrix[1] * vX + matrix[4] * vY + matrix[7] * vZ;
- const z = matrix[2] * vX + matrix[5] * vY + matrix[8] * vZ;
- result.x = x;
- result.y = y;
- result.z = z;
- return result;
- };
- /**
- * Computes the product of a matrix and a scalar.
- *
- * @param {Matrix3} matrix The matrix.
- * @param {number} scalar The number to multiply by.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- */
- Matrix3.multiplyByScalar = function (matrix, scalar, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.number("scalar", scalar);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result[0] = matrix[0] * scalar;
- result[1] = matrix[1] * scalar;
- result[2] = matrix[2] * scalar;
- result[3] = matrix[3] * scalar;
- result[4] = matrix[4] * scalar;
- result[5] = matrix[5] * scalar;
- result[6] = matrix[6] * scalar;
- result[7] = matrix[7] * scalar;
- result[8] = matrix[8] * scalar;
- return result;
- };
- /**
- * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.
- *
- * @param {Matrix3} matrix The matrix on the left-hand side.
- * @param {Cartesian3} scale The non-uniform scale on the right-hand side.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- *
- * @example
- * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromScale(scale), m);
- * Cesium.Matrix3.multiplyByScale(m, scale, m);
- *
- * @see Matrix3.multiplyByUniformScale
- * @see Matrix3.fromScale
- * @see Matrix3.fromUniformScale
- * @see Matrix3.setScale
- * @see Matrix3.setUniformScale
- * @see Matrix3.getScale
- */
- Matrix3.multiplyByScale = function (matrix, scale, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("scale", scale);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result[0] = matrix[0] * scale.x;
- result[1] = matrix[1] * scale.x;
- result[2] = matrix[2] * scale.x;
- result[3] = matrix[3] * scale.y;
- result[4] = matrix[4] * scale.y;
- result[5] = matrix[5] * scale.y;
- result[6] = matrix[6] * scale.z;
- result[7] = matrix[7] * scale.z;
- result[8] = matrix[8] * scale.z;
- return result;
- };
- /**
- * Computes the product of a matrix times a uniform scale, as if the scale were a scale matrix.
- *
- * @param {Matrix3} matrix The matrix on the left-hand side.
- * @param {number} scale The uniform scale on the right-hand side.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- * @example
- * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromUniformScale(scale), m);
- * Cesium.Matrix3.multiplyByUniformScale(m, scale, m);
- *
- * @see Matrix3.multiplyByScale
- * @see Matrix3.fromScale
- * @see Matrix3.fromUniformScale
- * @see Matrix3.setScale
- * @see Matrix3.setUniformScale
- * @see Matrix3.getScale
- */
- Matrix3.multiplyByUniformScale = function (matrix, scale, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.number("scale", scale);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result[0] = matrix[0] * scale;
- result[1] = matrix[1] * scale;
- result[2] = matrix[2] * scale;
- result[3] = matrix[3] * scale;
- result[4] = matrix[4] * scale;
- result[5] = matrix[5] * scale;
- result[6] = matrix[6] * scale;
- result[7] = matrix[7] * scale;
- result[8] = matrix[8] * scale;
- return result;
- };
- /**
- * Creates a negated copy of the provided matrix.
- *
- * @param {Matrix3} matrix The matrix to negate.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- */
- Matrix3.negate = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result[0] = -matrix[0];
- result[1] = -matrix[1];
- result[2] = -matrix[2];
- result[3] = -matrix[3];
- result[4] = -matrix[4];
- result[5] = -matrix[5];
- result[6] = -matrix[6];
- result[7] = -matrix[7];
- result[8] = -matrix[8];
- return result;
- };
- /**
- * Computes the transpose of the provided matrix.
- *
- * @param {Matrix3} matrix The matrix to transpose.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- */
- Matrix3.transpose = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const column0Row0 = matrix[0];
- const column0Row1 = matrix[3];
- const column0Row2 = matrix[6];
- const column1Row0 = matrix[1];
- const column1Row1 = matrix[4];
- const column1Row2 = matrix[7];
- const column2Row0 = matrix[2];
- const column2Row1 = matrix[5];
- const column2Row2 = matrix[8];
- result[0] = column0Row0;
- result[1] = column0Row1;
- result[2] = column0Row2;
- result[3] = column1Row0;
- result[4] = column1Row1;
- result[5] = column1Row2;
- result[6] = column2Row0;
- result[7] = column2Row1;
- result[8] = column2Row2;
- return result;
- };
- function computeFrobeniusNorm(matrix) {
- let norm = 0.0;
- for (let i = 0; i < 9; ++i) {
- const temp = matrix[i];
- norm += temp * temp;
- }
- return Math.sqrt(norm);
- }
- const rowVal = [1, 0, 0];
- const colVal = [2, 2, 1];
- function offDiagonalFrobeniusNorm(matrix) {
- // Computes the "off-diagonal" Frobenius norm.
- // Assumes matrix is symmetric.
- let norm = 0.0;
- for (let i = 0; i < 3; ++i) {
- const temp = matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])];
- norm += 2.0 * temp * temp;
- }
- return Math.sqrt(norm);
- }
- function shurDecomposition(matrix, result) {
- // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
- // section 8.4.2 The 2by2 Symmetric Schur Decomposition.
- //
- // The routine takes a matrix, which is assumed to be symmetric, and
- // finds the largest off-diagonal term, and then creates
- // a matrix (result) which can be used to help reduce it
- const tolerance = Math$1.CesiumMath.EPSILON15;
- let maxDiagonal = 0.0;
- let rotAxis = 1;
- // find pivot (rotAxis) based on max diagonal of matrix
- for (let i = 0; i < 3; ++i) {
- const temp = Math.abs(
- matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])]
- );
- if (temp > maxDiagonal) {
- rotAxis = i;
- maxDiagonal = temp;
- }
- }
- let c = 1.0;
- let s = 0.0;
- const p = rowVal[rotAxis];
- const q = colVal[rotAxis];
- if (Math.abs(matrix[Matrix3.getElementIndex(q, p)]) > tolerance) {
- const qq = matrix[Matrix3.getElementIndex(q, q)];
- const pp = matrix[Matrix3.getElementIndex(p, p)];
- const qp = matrix[Matrix3.getElementIndex(q, p)];
- const tau = (qq - pp) / 2.0 / qp;
- let t;
- if (tau < 0.0) {
- t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));
- } else {
- t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));
- }
- c = 1.0 / Math.sqrt(1.0 + t * t);
- s = t * c;
- }
- result = Matrix3.clone(Matrix3.IDENTITY, result);
- result[Matrix3.getElementIndex(p, p)] = result[
- Matrix3.getElementIndex(q, q)
- ] = c;
- result[Matrix3.getElementIndex(q, p)] = s;
- result[Matrix3.getElementIndex(p, q)] = -s;
- return result;
- }
- const jMatrix = new Matrix3();
- const jMatrixTranspose = new Matrix3();
- /**
- * Computes the eigenvectors and eigenvalues of a symmetric matrix.
- * <p>
- * Returns a diagonal matrix and unitary matrix such that:
- * <code>matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)</code>
- * </p>
- * <p>
- * The values along the diagonal of the diagonal matrix are the eigenvalues. The columns
- * of the unitary matrix are the corresponding eigenvectors.
- * </p>
- *
- * @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.
- * @param {object} [result] An object with unitary and diagonal properties which are matrices onto which to store the result.
- * @returns {object} An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.
- *
- * @example
- * const a = //... symetric matrix
- * const result = {
- * unitary : new Cesium.Matrix3(),
- * diagonal : new Cesium.Matrix3()
- * };
- * Cesium.Matrix3.computeEigenDecomposition(a, result);
- *
- * const unitaryTranspose = Cesium.Matrix3.transpose(result.unitary, new Cesium.Matrix3());
- * const b = Cesium.Matrix3.multiply(result.unitary, result.diagonal, new Cesium.Matrix3());
- * Cesium.Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a
- *
- * const lambda = Cesium.Matrix3.getColumn(result.diagonal, 0, new Cesium.Cartesian3()).x; // first eigenvalue
- * const v = Cesium.Matrix3.getColumn(result.unitary, 0, new Cesium.Cartesian3()); // first eigenvector
- * const c = Cesium.Cartesian3.multiplyByScalar(v, lambda, new Cesium.Cartesian3()); // equal to Cesium.Matrix3.multiplyByVector(a, v)
- */
- Matrix3.computeEigenDecomposition = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- //>>includeEnd('debug');
- // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
- // section 8.4.3 The Classical Jacobi Algorithm
- const tolerance = Math$1.CesiumMath.EPSILON20;
- const maxSweeps = 10;
- let count = 0;
- let sweep = 0;
- if (!defaultValue.defined(result)) {
- result = {};
- }
- const unitaryMatrix = (result.unitary = Matrix3.clone(
- Matrix3.IDENTITY,
- result.unitary
- ));
- const diagMatrix = (result.diagonal = Matrix3.clone(matrix, result.diagonal));
- const epsilon = tolerance * computeFrobeniusNorm(diagMatrix);
- while (sweep < maxSweeps && offDiagonalFrobeniusNorm(diagMatrix) > epsilon) {
- shurDecomposition(diagMatrix, jMatrix);
- Matrix3.transpose(jMatrix, jMatrixTranspose);
- Matrix3.multiply(diagMatrix, jMatrix, diagMatrix);
- Matrix3.multiply(jMatrixTranspose, diagMatrix, diagMatrix);
- Matrix3.multiply(unitaryMatrix, jMatrix, unitaryMatrix);
- if (++count > 2) {
- ++sweep;
- count = 0;
- }
- }
- return result;
- };
- /**
- * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
- *
- * @param {Matrix3} matrix The matrix with signed elements.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- */
- Matrix3.abs = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- result[0] = Math.abs(matrix[0]);
- result[1] = Math.abs(matrix[1]);
- result[2] = Math.abs(matrix[2]);
- result[3] = Math.abs(matrix[3]);
- result[4] = Math.abs(matrix[4]);
- result[5] = Math.abs(matrix[5]);
- result[6] = Math.abs(matrix[6]);
- result[7] = Math.abs(matrix[7]);
- result[8] = Math.abs(matrix[8]);
- return result;
- };
- /**
- * Computes the determinant of the provided matrix.
- *
- * @param {Matrix3} matrix The matrix to use.
- * @returns {number} The value of the determinant of the matrix.
- */
- Matrix3.determinant = function (matrix) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- //>>includeEnd('debug');
- const m11 = matrix[0];
- const m21 = matrix[3];
- const m31 = matrix[6];
- const m12 = matrix[1];
- const m22 = matrix[4];
- const m32 = matrix[7];
- const m13 = matrix[2];
- const m23 = matrix[5];
- const m33 = matrix[8];
- return (
- m11 * (m22 * m33 - m23 * m32) +
- m12 * (m23 * m31 - m21 * m33) +
- m13 * (m21 * m32 - m22 * m31)
- );
- };
- /**
- * Computes the inverse of the provided matrix.
- *
- * @param {Matrix3} matrix The matrix to invert.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- *
- * @exception {DeveloperError} matrix is not invertible.
- */
- Matrix3.inverse = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- const m11 = matrix[0];
- const m21 = matrix[1];
- const m31 = matrix[2];
- const m12 = matrix[3];
- const m22 = matrix[4];
- const m32 = matrix[5];
- const m13 = matrix[6];
- const m23 = matrix[7];
- const m33 = matrix[8];
- const determinant = Matrix3.determinant(matrix);
- //>>includeStart('debug', pragmas.debug);
- if (Math.abs(determinant) <= Math$1.CesiumMath.EPSILON15) {
- throw new Check.DeveloperError("matrix is not invertible");
- }
- //>>includeEnd('debug');
- result[0] = m22 * m33 - m23 * m32;
- result[1] = m23 * m31 - m21 * m33;
- result[2] = m21 * m32 - m22 * m31;
- result[3] = m13 * m32 - m12 * m33;
- result[4] = m11 * m33 - m13 * m31;
- result[5] = m12 * m31 - m11 * m32;
- result[6] = m12 * m23 - m13 * m22;
- result[7] = m13 * m21 - m11 * m23;
- result[8] = m11 * m22 - m12 * m21;
- const scale = 1.0 / determinant;
- return Matrix3.multiplyByScalar(result, scale, result);
- };
- const scratchTransposeMatrix = new Matrix3();
- /**
- * Computes the inverse transpose of a matrix.
- *
- * @param {Matrix3} matrix The matrix to transpose and invert.
- * @param {Matrix3} result The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter.
- */
- Matrix3.inverseTranspose = function (matrix, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object("matrix", matrix);
- Check.Check.typeOf.object("result", result);
- //>>includeEnd('debug');
- return Matrix3.inverse(
- Matrix3.transpose(matrix, scratchTransposeMatrix),
- result
- );
- };
- /**
- * Compares the provided matrices componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {Matrix3} [left] The first matrix.
- * @param {Matrix3} [right] The second matrix.
- * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
- */
- Matrix3.equals = function (left, right) {
- return (
- left === right ||
- (defaultValue.defined(left) &&
- defaultValue.defined(right) &&
- left[0] === right[0] &&
- left[1] === right[1] &&
- left[2] === right[2] &&
- left[3] === right[3] &&
- left[4] === right[4] &&
- left[5] === right[5] &&
- left[6] === right[6] &&
- left[7] === right[7] &&
- left[8] === right[8])
- );
- };
- /**
- * Compares the provided matrices componentwise and returns
- * <code>true</code> if they are within the provided epsilon,
- * <code>false</code> otherwise.
- *
- * @param {Matrix3} [left] The first matrix.
- * @param {Matrix3} [right] The second matrix.
- * @param {number} [epsilon=0] The epsilon to use for equality testing.
- * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
- */
- Matrix3.equalsEpsilon = function (left, right, epsilon) {
- epsilon = defaultValue.defaultValue(epsilon, 0);
- return (
- left === right ||
- (defaultValue.defined(left) &&
- defaultValue.defined(right) &&
- Math.abs(left[0] - right[0]) <= epsilon &&
- Math.abs(left[1] - right[1]) <= epsilon &&
- Math.abs(left[2] - right[2]) <= epsilon &&
- Math.abs(left[3] - right[3]) <= epsilon &&
- Math.abs(left[4] - right[4]) <= epsilon &&
- Math.abs(left[5] - right[5]) <= epsilon &&
- Math.abs(left[6] - right[6]) <= epsilon &&
- Math.abs(left[7] - right[7]) <= epsilon &&
- Math.abs(left[8] - right[8]) <= epsilon)
- );
- };
- /**
- * An immutable Matrix3 instance initialized to the identity matrix.
- *
- * @type {Matrix3}
- * @constant
- */
- Matrix3.IDENTITY = Object.freeze(
- new Matrix3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
- );
- /**
- * An immutable Matrix3 instance initialized to the zero matrix.
- *
- * @type {Matrix3}
- * @constant
- */
- Matrix3.ZERO = Object.freeze(
- new Matrix3(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
- );
- /**
- * The index into Matrix3 for column 0, row 0.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN0ROW0 = 0;
- /**
- * The index into Matrix3 for column 0, row 1.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN0ROW1 = 1;
- /**
- * The index into Matrix3 for column 0, row 2.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN0ROW2 = 2;
- /**
- * The index into Matrix3 for column 1, row 0.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN1ROW0 = 3;
- /**
- * The index into Matrix3 for column 1, row 1.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN1ROW1 = 4;
- /**
- * The index into Matrix3 for column 1, row 2.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN1ROW2 = 5;
- /**
- * The index into Matrix3 for column 2, row 0.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN2ROW0 = 6;
- /**
- * The index into Matrix3 for column 2, row 1.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN2ROW1 = 7;
- /**
- * The index into Matrix3 for column 2, row 2.
- *
- * @type {number}
- * @constant
- */
- Matrix3.COLUMN2ROW2 = 8;
- Object.defineProperties(Matrix3.prototype, {
- /**
- * Gets the number of items in the collection.
- * @memberof Matrix3.prototype
- *
- * @type {number}
- */
- length: {
- get: function () {
- return Matrix3.packedLength;
- },
- },
- });
- /**
- * Duplicates the provided Matrix3 instance.
- *
- * @param {Matrix3} [result] The object onto which to store the result.
- * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
- */
- Matrix3.prototype.clone = function (result) {
- return Matrix3.clone(this, result);
- };
- /**
- * Compares this matrix to the provided matrix componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {Matrix3} [right] The right hand side matrix.
- * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
- */
- Matrix3.prototype.equals = function (right) {
- return Matrix3.equals(this, right);
- };
- /**
- * @private
- */
- Matrix3.equalsArray = function (matrix, array, offset) {
- return (
- matrix[0] === array[offset] &&
- matrix[1] === array[offset + 1] &&
- matrix[2] === array[offset + 2] &&
- matrix[3] === array[offset + 3] &&
- matrix[4] === array[offset + 4] &&
- matrix[5] === array[offset + 5] &&
- matrix[6] === array[offset + 6] &&
- matrix[7] === array[offset + 7] &&
- matrix[8] === array[offset + 8]
- );
- };
- /**
- * Compares this matrix to the provided matrix componentwise and returns
- * <code>true</code> if they are within the provided epsilon,
- * <code>false</code> otherwise.
- *
- * @param {Matrix3} [right] The right hand side matrix.
- * @param {number} [epsilon=0] The epsilon to use for equality testing.
- * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
- */
- Matrix3.prototype.equalsEpsilon = function (right, epsilon) {
- return Matrix3.equalsEpsilon(this, right, epsilon);
- };
- /**
- * Creates a string representing this Matrix with each row being
- * on a separate line and in the format '(column0, column1, column2)'.
- *
- * @returns {string} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2)'.
- */
- Matrix3.prototype.toString = function () {
- return (
- `(${this[0]}, ${this[3]}, ${this[6]})\n` +
- `(${this[1]}, ${this[4]}, ${this[7]})\n` +
- `(${this[2]}, ${this[5]}, ${this[8]})`
- );
- };
- exports.Cartesian3 = Cartesian3;
- exports.Cartographic = Cartographic;
- exports.Ellipsoid = Ellipsoid;
- exports.Matrix3 = Matrix3;
- }));
|