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)
????}
}