cesium 常見(jiàn)坐標(biāo)系及坐標(biāo)轉(zhuǎn)換(工具篇)

ceisum里面的常見(jiàn)坐標(biāo)系包括

1.屏幕坐標(biāo)

2.世界坐標(biāo)(笛卡爾直角坐標(biāo))

3.經(jīng)緯度雄家,可以是弧度形式和度的形式

4.WebMercator web墨卡托

5.歐拉角

6.四元數(shù)

看一張我自己畫(huà)的圖嘹黔,整理了他們之間的關(guān)系


下面提供坐標(biāo)轉(zhuǎn)換的代碼 github地址?


/*

?*?@Description:?坐標(biāo)轉(zhuǎn)換工具,下面的坐標(biāo)轉(zhuǎn)換默認(rèn)都是基于WGS84?橢球體

?*/

class?Degrees?{

????constructor(longitude,?latitude,?height?=?0)?{

????????this.longitude?=?longitude;

????????this.latitude?=?latitude;

????????this.height?=?height;

????}

}

Cesium.Degrees?=?Degrees;//不建議這樣直接修改Cesium原始對(duì)象

class?Tramsform?{

????/**?

?????*?@description:?弧度轉(zhuǎn)度

?????*?@param?{Number}?value?

?????*?@return?{Number}?

?????*/

????toDegrees(value)?{

????????return?Cesium.Math.toDegrees(value)

????}

????/**

?????*?@description:?度轉(zhuǎn)弧度

?????*/

????toRadians(value)?{

????????return?Cesium.Math.toRadians(value)

????}

????/**

?????*?@description:?經(jīng)緯度(度)轉(zhuǎn)世界坐標(biāo)

?????*?@param?{Degrees}?degrees.longitude?經(jīng)度?degrees.latitude?緯度?degrees.height高度

?????*?@return?{Cartesian3}?世界坐標(biāo)

?????*/

????degreesToCartesian(degrees)?{

????????return?Cesium.Cartesian3.fromDegrees(degrees.longitude,?degrees.latitude,?degrees.height)

????}

????/*

????*?@description:?世界坐標(biāo)轉(zhuǎn)?經(jīng)緯度(度)

????*?@param?{Cartesian3}?cartesian?世界坐標(biāo)

????*?@return?{Cartographic}??返回轉(zhuǎn)換之后的經(jīng)緯度

????*/

????degreesFromCartesian(cartesian)?{

????????let?cartographic?=?this.cartographicFromCartesian(cartesian);

????????return?this.degreesFromCartographic(cartographic);

????}

????/*

???*?@description:?經(jīng)緯度(度)轉(zhuǎn)經(jīng)緯度(弧度)

???*?@param?{*}?degrees

???*?@return?{*}

???*/

????degreesToCartographic(degrees)?{

????????degrees.longitude?=?this.toRadians(degrees.longitude);

????????degrees.latitude?=?this.toRadians(degrees.latitude);

????????return?degrees;

????}

????/**

?????*?@description:?經(jīng)緯度(弧度)轉(zhuǎn)經(jīng)緯度(度)

?????*?@param?{Cartographic}?cartographic

?????*?@return?{*}?返回經(jīng)緯度(度)

?????*/

????degreesFromCartographic(cartographic)?{

????????cartographic.longitude?=?this.toDegrees(cartographic.longitude);

????????cartographic.latitude?=?this.toDegrees(cartographic.latitude);

????????return?cartographic;

????}

????/**?

?????*?@description:?經(jīng)緯度(度)坐標(biāo)轉(zhuǎn)web墨卡托坐標(biāo)

?????*?@param?{Cartographic}?degrees

?????*?@return?{Cartesian3}?web墨卡托坐標(biāo)

?????*/

????degreesToWebMercatorProjection(degrees)?{

????????var?webMercatorProjection?=?new?Cesium.WebMercatorProjection();

????????return?webMercatorProjection.project(this.degreesToCartesian(degrees))

????}

????/**?

?????*?@description:?web墨卡托轉(zhuǎn)經(jīng)緯度(度)

?????*?@param?{Cartesian3}?cartesian

?????*?@return?{Cartographic}?經(jīng)緯度(度)坐標(biāo)

?????*/

????degreesFromWebMercatorProjection(cartesian)?{

????????var?webMercatorProjection?=?new?Cesium.WebMercatorProjection();

????????return?this.degreesFromCartographic(webMercatorProjection.unproject(cartesian))

????}

????/**

?????*?@description:?弧度坐標(biāo)轉(zhuǎn)世界坐標(biāo)

?????*?@param?{Cartographic}???cartographic.longitude?經(jīng)度

?????*?@param?{Cartographic}???cartographic.latitude?緯度

?????*?@param?{Cartographic}???cartographic.height?高度

?????*?@return?{Cartesian3}?世界坐標(biāo)

?????*/

????cartographicToCartesian(cartographic)?{

????????return?Cesium.Cartographic.toCartesian(cartographic)

????}

????/**

?????*?@description:?世界坐標(biāo)轉(zhuǎn)經(jīng)緯度弧度

?????*?@param?{Cartesian3}?cartesian?世界坐標(biāo)

?????*?@return?{Cartographic}??返回轉(zhuǎn)換之后的經(jīng)緯度弧度坐標(biāo)

?????*/

????cartographicFromCartesian(cartesian)?{

????????return?Cesium.Cartographic.fromCartesian(cartesian)

????}

????/**

?????*?@description:?經(jīng)緯度度轉(zhuǎn)經(jīng)緯度弧度

?????*?@param?{Degrees}?degrees.longitude?經(jīng)度?degrees.latitude?緯度?degrees.height高度

?????*?@return?{*}

?????*/

????cartographicFromDegrees(degrees)?{

????????return?this.degreesToCartographic(degrees)

????}

????/**

???????*?@description:?經(jīng)緯度(弧度)轉(zhuǎn)經(jīng)緯度(度)

???????*?@param?{Cartographic}?cartographic

???????*?@return?{*}?返回經(jīng)緯度(度)

???????*/

????cartographicToDegrees(cartographic)?{

????????return?this.degreesFromCartographic(cartographic)

????}

????/**?

?????*?@description:?經(jīng)緯度(弧度)坐標(biāo)轉(zhuǎn)web墨卡托坐標(biāo)

?????*?@param?{Cartographic}?cartographic

?????*?@return?{Cartesian3}?web墨卡托坐標(biāo)

?????*/

????cartographicToWebMercatorProjection(cartographic)?{

????????var?webMercatorProjection?=?new?Cesium.WebMercatorProjection();

????????return?webMercatorProjection.project(cartographic)

????}

????/**?

?????*?@description:?web墨卡托轉(zhuǎn)經(jīng)緯度(弧度)

?????*?@param?{Cartesian3}?cartesian

?????*?@return?{Cartographic}?弧度坐標(biāo)

?????*/

????cartographicFromWebMercatorProjection(cartesian)?{

????????var?webMercatorProjection?=?new?Cesium.WebMercatorProjection();

????????return?webMercatorProjection.unproject(cartesian)

????}

????/*

???*?@description:?世界坐標(biāo)轉(zhuǎn)?經(jīng)緯度(度)

???*?@param?{Cartesian3}?cartesian?世界坐標(biāo)

???*?@return?{Cartographic}??返回轉(zhuǎn)換之后的經(jīng)緯度

???*/

????cartesianToDegrees(cartesian)?{

????????return?this.degreesFromCartesian(cartesian)

????}

????/**

??*?@description:?經(jīng)緯度(度)轉(zhuǎn)世界坐標(biāo)

??*?@param?{Degrees}?degrees.longitude?經(jīng)度?degrees.latitude?緯度?degrees.height高度

??*?@return?{Cartesian3}?世界坐標(biāo)

??*/

????cartesianFormDegrees(degrees)?{

????????return?this.degreesToCartesian(degrees)

????}

????/**

????*?@description:?世界坐標(biāo)轉(zhuǎn)經(jīng)緯度(弧度)

????*?@param?{Cartesian3}?cartesian?世界坐標(biāo)

????*?@return?{Cartographic}??返回轉(zhuǎn)換之后的經(jīng)緯度弧度坐標(biāo)

????*/

????cartesianToCartographic(cartesian)?{

????????return?this.cartographicFromCartesian(cartesian)

????}

????/**

???*?@description:?弧度坐標(biāo)轉(zhuǎn)世界坐標(biāo)

???*?@param?{Cartographic}??cartographic.longitude?經(jīng)度

???*?@param?{Cartographic}??cartographic.latitude?緯度

???*?@param?{Cartographic}??cartographic.height?高度

???*?@return?{Cartesian3}?世界坐標(biāo)

???*/

????cartesianFromCartographic(cartographic)?{

????????return?this.cartographicToCartesian(cartographic)

????}

????/**

?????????*?@description:?世界坐標(biāo)坐標(biāo)轉(zhuǎn)web墨卡托坐標(biāo)

?????????*?@param?{Cartographic}?degrees

?????????*?@return?{Cartesian3}?web墨卡托坐標(biāo)

?????????*/

????cartesianToWebMercatorProjection(cartesian)?{

????????var?webMercatorProjection?=?new?Cesium.WebMercatorProjection();

????????return?webMercatorProjection.project(this.cartesianToCartographic(cartesian))

????}

????/**?

?????*?@description:?web墨卡托轉(zhuǎn)世界坐標(biāo)

?????*?@param?{Cartesian3}?cartesian

?????*?@return?{Cartographic}?世界坐標(biāo)

?????*/

????cartesianFromWebMercatorProjection(cartesian)?{

????????var?webMercatorProjection?=?new?Cesium.WebMercatorProjection();

????????return?this.cartesianFromCartographic(webMercatorProjection.unproject(cartesian))

????}

????/**?

?????*?@description:?世界坐標(biāo)轉(zhuǎn)屏幕坐標(biāo)

?????*?@param?{Cartesian3}?cartesian

?????*?@return?{Cartesian2}?屏幕坐標(biāo)

?????*/

????cartesianToWindowCoordinates(scene,?cartesian)?{

????????return?Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene,?cartesian)

????}

????/**?

?????*?@description:?從4*4矩陣中得到平移位置

?????*?@param?{Matrix4}?mat4?4*4矩陣

?????*?@return?{Cartesian3}?返回位置信息

?????*/

????getTranslationFromMatrix4(mat4,?result)?{

????????if?(!result)?result?=?new?Cesium.Cartesian3();

????????return?Cesium.Matrix4.getTranslation(mat4,?result)

????}

????/**?

?????*?@description:?返回x,y,z方向的比例尺信息

?????*?@param?{Matrix4}?mat4?4*4矩陣

?????*?@param?{Cartesian3}?result?用于儲(chǔ)存結(jié)果

?????*?@return?{Cartesian3}?返回x,y,z方向的比例尺信息

?????*/

????getScaleFromMatrix4(mat4,?result)?{

????????if?(!result)?result?=?new?Cesium.Cartesian3();

????????return?Cesium.Matrix4.getScale(mat4,?result)

????}

????/**?

?????*?@description:?將3*3旋轉(zhuǎn)矩陣轉(zhuǎn)換成齊次坐標(biāo)

?????*?@param?{Matrix4}?matrix?3*3矩陣

?????*?@param?{Quaternion}?result?儲(chǔ)存結(jié)果

?????*?@return?{Quaternion}?返回齊次坐標(biāo)

?????*/

????quaternionFromRotationMatrix(matrix,?result)?{

????????return?Cesium.Quaternion.fromRotationMatrix(matrix,?result)

????}

????/**?

?????*?@description:?將歐拉角轉(zhuǎn)成齊次坐標(biāo)

?????*?@param?{HeadingPitchRoll}?headingPitchRoll

?????*?@param?{Quaternion}?result?儲(chǔ)存結(jié)果

?????*?@return?{Quaternion}?返回齊次坐標(biāo)

?????*/

????quaternionfromHeadingPitchRoll(headingPitchRoll,?result)?{

????????return?Cesium.Quaternion.fromHeadingPitchRoll(headingPitchRoll,?result)

????}

????/**?

?????*?@description:?將齊次坐標(biāo)轉(zhuǎn)成歐拉角表示项戴,和quaternionfromHeadingPitchRoll方法互逆

?????*?@param?{Quaternion}?quaternion?齊次坐標(biāo)

?????*?@param?{HeadingPitchRoll}?result??儲(chǔ)存結(jié)果

?????*?@return?{HeadingPitchRoll}?返回歐拉角

?????*/

????headingPitchRollFromQuaternion(quaternion,?result)?{

????????return?Cesium.HeadingPitchRoll.fromQuaternion(quaternion,?result)

????}

????/**

?????*?@description:?從4*4矩陣中得到歐拉角

?????*?@param?{Matrix4}?transform?4*4矩陣

?????*?@param?{Ellipsoid}?ellipsoid?84橢球體

?????*?@param?{Transforms.LocalFrameToFixedFrame}?fixedFrameTransform?參考系,默認(rèn)東-北-上參考系

?????*?@param?{HeadingPitchRoll}?result?儲(chǔ)存結(jié)果

?????*?@return?{HeadingPitchRoll}

?????*/

????fixedFrameToHeadingPitchRoll(transform,?ellipsoid,?fixedFrameTransform,?result)?{

????????return?Cesium.Transforms.fixedFrameToHeadingPitchRoll(transform,?ellipsoid,?fixedFrameTransform,?result)

????}

????/**?

?????*?@description:?將歐拉角轉(zhuǎn)成3*3矩陣

?????*?@param?{HeadingPitchRoll}?headingPitchRoll

?????*?@param?{Matrix3}?result?儲(chǔ)存結(jié)果

?????*?@return?{Matrix3}?返回一個(gè)3*3矩陣

?????*/

????matrixFromHeadingPitchRoll(headingPitchRoll,?result)?{

????????return?Cesium.Matrix3.fromHeadingPitchRoll(headingPitchRoll,?result)

????}

????/**?

?????*?@description:?根據(jù)東-北-上方向參考系生成4*4矩陣,已知道地球上的某個(gè)位置活翩,可以根據(jù)這個(gè)方法生成一個(gè)4*4矩陣

?????*?@param?{Cartesian3}?origin?原點(diǎn)坐標(biāo)

?????*?@param?{Ellipsoid}?ellipsoid?84橢球體

?????*?@param?{Matrix4}?result?儲(chǔ)存結(jié)果

?????*?@return?{Matrix4}?返回4*4矩陣

?????*/

????eastNorthUpToFixedFrame(origin,?ellipsoid,?result)?{

????????return?Cesium.Transforms.eastNorthUpToFixedFrame(origin,?ellipsoid,?result)

????}

????/**?

?????*?@description:?根據(jù)原點(diǎn)和歐拉角生成4*4矩陣

?????*?@param?{Cartesian3}?origin?原點(diǎn)坐標(biāo)

?????*?@param?{HeadingPitchRoll}?headingPitchRoll?歐拉角

?????*?@param?{Ellipsoid}?ellipsoid

?????*?@param?{Transforms.LocalFrameToFixedFrame}?fixedFrameTransform?參考系涛酗,默認(rèn)為東-北-上參考系

?????*?@param?{Matrix4}?result?儲(chǔ)存結(jié)果

?????*?@return?{Matrix4}?返回4*4矩陣

?????*/

????headingPitchRollToFixedFrame(origin,?headingPitchRoll,?ellipsoid,?fixedFrameTransform,?result)?{

????????return?Cesium.Transforms.headingPitchRollToFixedFrame(origin,?headingPitchRoll,?ellipsoid,?fixedFrameTransform,?result)

????}

}






?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市沈跨,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌兔综,老刑警劉巖饿凛,帶你破解...
    沈念sama閱讀 211,376評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異软驰,居然都是意外死亡涧窒,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,126評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門(mén)锭亏,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)纠吴,“玉大人,你說(shuō)我怎么就攤上這事慧瘤〈饕眩” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,966評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵锅减,是天一觀(guān)的道長(zhǎng)糖儡。 經(jīng)常有香客問(wèn)我,道長(zhǎng)怔匣,這世上最難降的妖魔是什么握联? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,432評(píng)論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上金闽,老公的妹妹穿的比我還像新娘纯露。我一直安慰自己,他們只是感情好代芜,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,519評(píng)論 6 385
  • 文/花漫 我一把揭開(kāi)白布埠褪。 她就那樣靜靜地躺著,像睡著了一般蜒犯。 火紅的嫁衣襯著肌膚如雪组橄。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,792評(píng)論 1 290
  • 那天罚随,我揣著相機(jī)與錄音玉工,去河邊找鬼。 笑死淘菩,一個(gè)胖子當(dāng)著我的面吹牛遵班,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播潮改,決...
    沈念sama閱讀 38,933評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼狭郑,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了汇在?” 一聲冷哼從身側(cè)響起翰萨,我...
    開(kāi)封第一講書(shū)人閱讀 37,701評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎糕殉,沒(méi)想到半個(gè)月后亩鬼,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,143評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡阿蝶,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,488評(píng)論 2 327
  • 正文 我和宋清朗相戀三年雳锋,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片羡洁。...
    茶點(diǎn)故事閱讀 38,626評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡玷过,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出筑煮,到底是詐尸還是另有隱情辛蚊,我是刑警寧澤,帶...
    沈念sama閱讀 34,292評(píng)論 4 329
  • 正文 年R本政府宣布真仲,位于F島的核電站嚼隘,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏袒餐。R本人自食惡果不足惜飞蛹,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,896評(píng)論 3 313
  • 文/蒙蒙 一谤狡、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧卧檐,春花似錦墓懂、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,742評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至盈罐,卻和暖如春榜跌,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背盅粪。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來(lái)泰國(guó)打工钓葫, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人票顾。 一個(gè)月前我還...
    沈念sama閱讀 46,324評(píng)論 2 360
  • 正文 我出身青樓础浮,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親奠骄。 傳聞我的和親對(duì)象是個(gè)殘疾皇子豆同,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,494評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容