首页 > 其他分享 >Cesium Transform(二十)

Cesium Transform(二十)

时间:2023-03-01 18:34:18浏览次数:36  
标签:二十 Cartesian3 Transform transform var Transforms Cesium new

cesium是一个用于创建3D地球和空间场景的JavaScript库,它提供了一些用于坐标变换的类,统称为transform。transform类可以帮助我们在不同的参考系之间转换点或向量,例如从地球固定系到国际天文参考系,或者从WGS84坐标系到窗口坐标系。transform类还可以根据给定的位置和方向创建一个变换矩阵,例如从东北上到地球固定系,或者从局部坐标系到世界坐标系。

cesium中最常用的transform类有以下几个:

- Transforms.computeFixedToIcrfMatrix(date, result):计算一个旋转矩阵,将一个点或向量从地球固定系(ITRF)变换到国际天文参考系(GCRF/ICRF)惯性系。
- Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, result):根据给定的原点和椭球体创建一个变换矩阵,将一个点或向量从东北上(ENU)局部坐标系变换到地球固定系。
- Transforms.localFrameToFixedFrameGenerator(firstAxis, secondAxis):返回一个函数,该函数根据给定的位置和方向创建一个变换矩阵,将一个点或向量从局部坐标系变换到地球固定系。
- Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result):根据给定的原点、航偏俯角(HPR)和椭球体创建一个变换矩阵,将一个点或向量从HPR局部坐标系变换到地球固定系。

cesium还提供了一些用于在场景中转换位置的类:

- SceneTransforms.wgs84ToWindowCoordinates(scene, position, result):将WGS84坐标系中的位置转换为窗口坐标系中的位置。这通常用于将HTML元素放置在场景中某个对象的相同屏幕位置。
- SceneTransforms.wgs84ToDrawingBufferCoordinates(scene, position, result):将WGS84坐标系中的位置转换为绘图缓冲区坐标系中的位置。这通常用于在WebGL上下文中绘制与场景中某个对象对齐的图形。

除了上述类之外,cesium还有一些其他与模型、相机、投影等相关的transform类。可以在cesium文档中查看更多信息。

 

- Transforms.computeFixedToIcrfMatrix(date, result):这个方法接受一个日期参数和一个可选的结果参数,返回一个3x3的旋转矩阵,将一个点或向量从地球固定系(ITRF)变换到国际天文参考系(GCRF/ICRF)惯性系。这个方法可以用于将地球上的位置转换为太阳系中的位置。例如,如果你想知道现在地球上某个点在太阳系中的位置,你可以这样做¹:

// Get the position of a point on Earth in ITRF coordinates
var cartographic = Cesium.Cartographic.fromDegrees(-75.59777, 40.03883);
var pointInFixed = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude);

// Transform point to the ICRF axes
var now = Cesium.JulianDate.now();
var fixedToIcrf = Cesium.Transforms.computeFixedToIcrfMatrix(now);
var pointInInertial = new Cesium.Cartesian3();
Cesium.Matrix3.multiplyByVector(fixedToIcrf, pointInFixed, pointInInertial);

 

- Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, result):这个方法接受一个原点参数、一个椭球体参数和一个可选的结果参数,返回一个4x4的变换矩阵,将一个点或向量从东北上(ENU)局部坐标系变换到地球固定系。这个方法可以用于创建以某个位置为中心的局部参考系。例如,如果你想在地图上添加一个以某个位置为中心的方向指示器,你可以这样做¹:

// Get the transform from local east-north-up at cartographic (0.0, 0.0) to Earth's fixed frame.
const center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
const transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);

// Create a primitive that uses this transform
const scene = viewer.scene;
const primitive = scene.primitives.add(new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.SimplePolylineGeometry({
positions: [new Cesium.Cartesian3(0.0, 0.0, 0.0), new Cesium.Cartesian3(10000000.0, 0.0, 0.0)],
colors: [Cesium.Color.RED.withAlpha(1), Cesium.Color.RED.withAlpha(1)],
followSurface: false,
}),
modelMatrix: transform,
}),
appearance: new Cesium.PolylineColorAppearance(),
}));

 

- Transforms.localFrameToFixedFrameGenerator(firstAxis, secondAxis):这个方法接受两个轴参数(X、Y或Z),返回一个函数,该函数根据给定的位置和方向创建一个变换矩阵,将一个点或向量从局部坐标系变换到地球固定系。这个方法可以用于创建不同类型的局部参考系。例如,如果你想创建以北为第一轴、东为第二轴、上为第三轴(NEU)的局部参考系,你可以这样做:

// Create a local reference frame based on north-east-up axes at cartographic (11.34 degrees east longitude,
// 46 degrees north latitude).
const originCartographic = new Cesium.Cartographic(Cesium.Math.toRadians(11.34), Math.toRadians(46));
const originCartesian = viewer.scene.globe.

 

- BoundingSphere.fromTransformation(transformation, result):这个方法接受一个变换矩阵参数和一个可选的结果参数,返回一个紧密包围给定变换矩阵的包围球。这个方法可以用于计算变换后的几何体或模型的包围球。例如,如果你想计算一个模型在地球上某个位置旋转后的包围球,你可以这样做²:

// Load a model
var model = scene.primitives.add(Cesium.Model.fromGltf({
url : 'model.gltf',
}));

// Get the model's bounding sphere
var boundingSphere = model.boundingSphere;

// Create a transform matrix that rotates the model by 45 degrees around the z-axis at a certain position on Earth
var position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
var heading = Cesium.Math.toRadians(45.0);
var pitch = 0;
var roll = 0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
var transform = Cesium.Matrix4.fromTranslationQuaternionRotationScale(position, orientation, new Cesium.Cartesian3(1.0, 1.0, 1.0));

// Compute the transformed bounding sphere
var transformedBoundingSphere = Cesium.BoundingSphere.fromTransformation(transform, boundingSphere);

 

- TransformEditor(options):这是一个工具类,用于编辑对象(如模型、实体、图元等)的变换(位置、方向、缩放)。它接受一个选项对象参数,该参数可以指定要编辑的对象、场景、容器元素等属性。这个工具类可以用于交互式地调整对象在场景中的显示效果。例如,如果你想在场景中添加一个模型,并使用TransformEditor来编辑它,你可以这样做³:

// Create a scene
const viewer = new Cesium.Viewer("cesiumContainer");

// Add a model to the scene
const modelEntity = viewer.entities.add({
name: "model",
position: Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706),
orientation: Cesium.Transforms.headingPitchRollQuaternion(
Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706),
new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(135), 0, 0)
),
model: {
uri: "model.gltf",
minimumPixelSize: 128,
maximumScale: 20000,
},
});

// Create a TransformEditor instance and pass in the entity to edit
const transformEditor = new Cesium.TransformEditor({
entity: modelEntity,
});

 

- Model(modelOptions):这是一个表示三维模型(如glTF格式)的类,它接受一个模型选项对象参数,该参数可以指定模型的URL、位置、方向、缩放等属性。它还有一些方法和属性来控制模型的动画、着色器、材质等效果。这个类可以用于在场景中渲染复杂和精细的三维物体。例如,如果你想在场景中添加一个飞机模型,并让它沿着一条路径飞行,你可以这样做⁴:

// Create a scene
const viewer = new Cesium.Viewer("cesiumContainer");

// Create a path for the airplane to follow
const start = Cesium.JulianDate.fromDate(new Date(2015, 2, 25));
const

 

- Transforms.computeFixedToIcrfMatrix(date, result):这个方法接受一个日期参数和一个可选的结果参数,返回一个从地球固定坐标系到国际天文参考系(ICRF)坐标系的变换矩阵。这个方法可以用于将地球上的位置转换为太阳系中的位置。例如,如果你想计算2020年1月1日午夜时刻,在纬度0度经度0度处的位置在太阳系中的坐标,你可以这样做¹:

// Create a date object
var date = new Cesium.JulianDate.fromDate(new Date(2020, 0, 1));

// Get the position on Earth in Cartesian coordinates
var positionOnEarth = Cesium.Cartesian3.fromDegrees(0.0, 0.0);

// Get the transform matrix from Earth fixed frame to ICRF frame
var transform = Cesium.Transforms.computeFixedToIcrfMatrix(date);

// Apply the transform to get the position in ICRF frame
var positionInSpace = Cesium.Matrix3.multiplyByVector(transform, positionOnEarth);

 

- Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, result):这个方法接受一个原点参数、一个可选的椭球参数和一个可选的结果参数,返回一个从东北上(ENU)局部坐标系到地球固定坐标系的变换矩阵。这个方法可以用于创建一个以给定点为原点、以东方为x轴、以北方为y轴、以垂直方向为z轴的局部参考系。例如,如果你想创建一个以纽约市为原点的局部参考系,并在其中添加一些图形元素,你可以这样做¹:

// Create a scene
const viewer = new Cesium.Viewer("cesiumContainer");

// Get the position of New York City in Cartesian coordinates
var origin = Cesium.Cartesian3.fromDegrees(-74.01881302800248, 40.69114333714821);

// Get the transform matrix from ENU frame to Earth fixed frame
var transform = Cesium.Transforms.eastNorthUpToFixedFrame(origin);

// Add a red sphere of radius 5 meters at the origin of the local frame
viewer.entities.add({
name: "Red sphere",
position: new Cesium.ConstantPositionProperty(origin),
ellipsoid: {
radii: new Cesium.Cartesian3(5.0, 5.0, 5.0),
material: Cesium.Color.RED,
},
});

// Add a blue box of dimensions 10 x 10 x 10 meters along the x-axis of the local frame
viewer.entities.add({
name: "Blue box",
position: new Cesium.ConstantPositionProperty(
Cesium.Matrix4.multiplyByPoint(transform, new Cesium.Cartesian3(10.0, 0.0, 0.0))
),
box: {
dimensions: new Cesium.Cartesian3(10.0, 10.0,

 



 

 



 

 

 

标签:二十,Cartesian3,Transform,transform,var,Transforms,Cesium,new
From: https://www.cnblogs.com/LJXXXX/p/17169296.html

相关文章

  • Cesium 数据请求管理 Request_八号风球867的博客
    cesium数据请求主要通过三个类完成:Resource,RequestScheduler,Request;1.Resource:负责资源请求,发起xml请求2.RequestScheduler:负责请求调度管理3.Request:请求参数......
  • 《DFZU2EG_4EV MPSoC之嵌入式Vitis开发指南》第二十一章 AXI DMA环路测试​
    AXIDMA环路测试​DMA(DirectMemoryAccess,直接存储器访问)是计算机科学中的一种内存访问技术。它允许某些计算机内部的硬件子系统可以独立地直接读写系统内存,而不需中央处......
  • 【cesium】 FlyLine飞行漫游路线
    cesiumFlyLine飞行漫游路线mars3d.FlyLine是实体类,提供飞行漫游路线控制。使用示例在后面一、需求:拿取请求的坐标数据集展示车辆或人员轨迹1.生成轨迹数据//创建......
  • Cesium 模型移动以及视角跟随(十九)
     以下是一段示例代码,目的是使某一物体运动并进行相机跟踪该代码创建了一个CesiumViewer对象,并在其中添加了一个名为“飞机”的实体对象。该实体具有模型、位置和路径三个......
  • stm32f407探索者开发板(二十二)——通用定时器基本原理讲解
    文章目录​​一、三种定时器的区别​​​​二、通用定时器特点​​​​2.1功能特点描述​​​​2.2计数器模式​​​​三、通用定时器工作过程​​​​四、附​​一、三种......
  • stm32f407探索者开发板(二十一)——窗口看门狗
    文章目录​​一、窗口看门狗概述​​​​1.1看门狗框图​​​​1.2窗口看门狗工作过程总结​​​​1.3超时时间​​​​1.4为什么需要窗口看门狗​​​​1.5其他注意事......
  • stm32f407探索者开发板(二十)——独立看门狗实验
    文章目录​​一、独立看门狗概述​​​​1.1独立看门狗​​​​二、常用寄存器和库函数配置​​​​2.1独立看门狗框图​​​​2.2键值寄存器IWDG_KR​​​​2.3预分频......
  • pytorch transforms
    transforms.Resize(size,interpolation=2)功能:改变图片大小为指定的尺寸size:输出图片的大小,如果size为(h,w)则输出尺寸和(h,w)一致,若为单值x,输出二维值图片时,则较小的边......
  • 第二十六天 购物车补充以及正则表达式
    一、购物车内容补充需要注意注释中的内容@login_authdefcheck_shop_car():file_path=os.path.join(db_path,'%s.json'%is_login.get('username'))with......
  • pandas中的agg&transform方法
    pandas中的agg&transform方法1聚合函数agg1.1介绍agg方法是pandas中用于数据集汇总的函数,它可以将聚合行为应用于一组函数(字符串、函数或名称),这些函数将被应用于每一......