Cesium剖面线分析

实现思路:
1、使用一条线段来进行剖面分析。
2、在开始点和结束点之间插值100个点。
3、把插值的点数据赋值到echart中展现出来
实现效果如下:
在这里插入图片描述
首先还是得把模型加载出来,这个就不多解释,可以参考我的另一篇添加3D模型

function addProfile(){
		// 具体事件的实现
		var ellipsoid = _this.viewer.scene.globe.ellipsoid
		var handler = new Cesium.ScreenSpaceEventHandler(_this.viewer.scene.canvas)
		var start, end
		var profile = {
			arrHB: [],
			arrPoint: [],
			ponits: [],
		}
		var draw = function (drawingMode) {
			var entityPolygon = null
			//淹没分析entity
			function createPoint(worldPosition) {
				var point = _this.viewer.entities.add({
					position: worldPosition,
					point: {
						pixelSize: 10,
						color: Cesium.Color.YELLOW,
						heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
					},
				})
				return point
			}

			var drawingMode = drawingMode
			function drawShape(positionData) {
				var shape
				if (drawingMode === 'line' && undefined != newProfile) {
					shape = _this.viewer.entities.add({
						polyline: {
							positions: positionData,
							clampToGround: true,
							arcType: Cesium.ArcType.RHUMB,
							material: Cesium.Color.GREEN,
							width: 3,
						},
					})
				} else if (drawingMode === 'polygon') {
					shape = _this.viewer.entities.add({
						polygon: {
							hierarchy: positionData,
							material: new Cesium.ColorMaterialProperty(
								Cesium.Color.LIGHTSKYBLUE.withAlpha(0.7)
							),
						},
					})
				}
				return shape
			}
			var activeShapePoints = []
			var activeShape
			var floatingPoint
			handler.setInputAction(function (event) {
				var earthPosition = _this.viewer.scene.pickPosition(event.position)
				if (Cesium.defined(earthPosition)) {
					if (activeShapePoints.length === 0) {
						start = earthPosition
						floatingPoint = createPoint(earthPosition)
						activeShapePoints.push(earthPosition)
						var dynamicPositions = new Cesium.CallbackProperty(function () {
							return activeShapePoints
						}, false)
						activeShape = drawShape(dynamicPositions)
					}
					activeShapePoints.push(earthPosition)
					createPoint(earthPosition)
				}
			}, Cesium.ScreenSpaceEventType.LEFT_CLICK)

			handler.setInputAction(function (event) {
				if (Cesium.defined(floatingPoint)) {
					var newPosition = _this.viewer.scene.pickPosition(event.endPosition)
					if (Cesium.defined(newPosition)) {
						floatingPoint.position.setValue(newPosition)
						activeShapePoints.pop()
						activeShapePoints.push(newPosition)
					}
				}
			}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)

			function terminateShape() {
				activeShapePoints.pop()
				entityPolygon = drawShape(activeShapePoints)
				_this.viewer.entities.remove(floatingPoint)
				_this.viewer.entities.remove(activeShape)
				entityPolygon = null
				floatingPoint = undefined
				activeShape = undefined
				activeShapePoints = []
			}

			handler.setInputAction(function (event) {
				var length = activeShapePoints.length - 1
				end = activeShapePoints[length]
				profileAnalyse(start, end)//开始分析
				// setEchartsData(profile)//设置echart
				terminateShape()
				handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)//移除左键事件	
				handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE)//移除移动事件	
				handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK)//移除右键事件	
			}, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
		}


		//剖面分析
		function profileAnalyse(start, end) {
			var scene = _this.viewer.scene;
			var startPoint = Cesium.Cartographic.fromCartesian(start)
			var endPoint = Cesium.Cartographic.fromCartesian(end)
			profile.ponits.push(start)
			profile.arrPoint.push(getDegrees(startPoint))
			profile.arrHB.push(startPoint.height)
			// 插值100个点,点越多模拟越精确,但是效率会低
			var count = 100;
			var arrHeight = []
			for (var i = 0; i < count; i++) {
				var cart = (Cesium.Cartesian3.lerp(
					start,
					end,
					i / count,
					new Cesium.Cartesian3()
				))
				arrHeight.push(cart)
			}
			//scene.clampToHeightMostDetailed获取模型样本高度,详情可查看cesium文档
			scene.clampToHeightMostDetailed(arrHeight).then(function (clampedCartesians) {
				for (var i = 0; i < count; i++) {
					profile.disc.push(distance(profile.ponits[i], Cesium.Cartographic.fromCartesian(clampedCartesians[i])))
					profile.ponits.push(clampedCartesians[i])
					profile.arrPoint.push(getDegrees(clampedCartesians[i]))
					profile.arrHB.push(Cesium.Cartographic.fromCartesian(clampedCartesians[i]).height)
				}
				profile.ponits.push(end)
				profile.arrPoint.push(getDegrees(endPoint))
				profile.arrHB.push(endPoint.height)
				setEchartsData(profile)
			})
		}

		//计算两点间的距离
		function distance(point1, point2) {
			/**根据经纬度计算出距离**/
			var geodesic = new Cesium.EllipsoidGeodesic()
			geodesic.setEndPoints(point1, point2)
			var s = geodesic.surfaceDistance
			//返回两点之间的距离
			s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2.height - point1.height, 2))
			return s
		}
		//世界坐标转换为经纬度
		function getDegrees(cart) {
			var cartographic = ellipsoid.cartesianToCartographic(cart)
			var lat = Cesium.Math.toDegrees(cartographic.latitude)
			var lng = Cesium.Math.toDegrees(cartographic.longitude)
			var alt = cartographic.height
			return { x: lng, y: lat, z: alt }
		}
		//经纬度保留两位小数
		function strFormat(str) {
			var strString = str.toString()
			var strs = strString.slice(0, strString.indexOf('.') + 3)
			return strs
		}

		//设置Echart数据
		function setEchartsData(e) {
			if (null != e && null != e.arrPoint && undefined != newProfile) {
				$('#sectionChars').show();
				var myChart = echarts.init(document.getElementById("echartsView1"), 'dark');
				var t = e.arrPoint,
					chartData = {
						grid: {
							left: 10,
							right: 10,
							bottom: 10,
							containLabel: !0,
						},
						tooltip: {
							trigger: 'axis',
							formatter: function (e) {
								var htmldiv = '';
								var r = t[e[0].dataIndex];
								return(
									htmldiv +=
									'所在位置:'+strFormat(r.x)+','+strFormat(r.y)+'<br/>'+							
									'高程值:'+haoutil.str.formatLength(e[0].value)+'<br/>'
									)
							},
						},
						xAxis:
						{
							name: '距离',
							type: 'category',
							boundaryGap: !1,
							axisLabel: {
								show: !1,
							},
							data: e.arrHB,
						},

						yAxis:
						{
							type: 'value',
							axisLabel: {
								rotate: 0,
								formatter: '{value} 米',
							},
						},

						series: [
							{
								name: '高程值',
								type: 'line',
								smooth: !0,
								symbol: 'none',
								sampling: 'average',
								itemStyle: {
									normal: {
										color: 'rgb(255, 70, 131)',
									},
								},
								areaStyle: {
									normal: {
										color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
											{
												offset: 0,
												color: 'rgb(255, 158, 68)',
											},
											{
												offset: 1,
												color: 'rgb(255, 70, 131)',
											},
										]),
									},
								},
								data: e.arrHB,
							},
						],
					}
				myChart.setOption(chartData)
			}
		}
		draw('line')
}
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
Cesium剖面分析是一种利用离子轨迹法研究材料剖面结构的分析方法。在这个过程中,通过将样品暴露于一个具有较高能量的离子束中,离子束会与样品表面的原子发生相互作用,引起剖面的改变。剖面形成过程中会发生离子在材料中的输运和沉积,从而形成一个复杂的剖面结构。 cesium剖面分析的原理是通过控制离子辐照能量、剂量和离子束的角度等参数,以及利用离子或电子束扫描进行表征和分析。具体而言,离子束轰击样品表面后,会发生离子表面相互作用、散射和快速输运等过程,从而形成剖面结构。这个过程可以通过离子束激发发射光谱(IBED)、离子退火和电子显微镜等技术进行表征和分析。 在cesium剖面分析中,常用的表征技术有二次离子质谱(SIMS)、弹性反冲离子散射(ERD)、能量分散X射线光谱(EDX)和透射电子显微镜等。这些技术可以提供样品剖面的元素分布、化学组成和晶体结构等信息,从而帮助研究人员了解材料的结构、性能和性质。 通过cesium剖面分析,可以研究材料的界面、薄膜、气敏性、杂质分布、化学反应机制等问题。这对于材料科学和表面化学的研究具有重要意义。同时,cesium剖面分析也广泛应用于半导体、光电子器件、电池、涂层材料、生物材料等领域的研究和开发中。 总之,cesium剖面分析是一种重要的材料剖面结构分析方法,可以通过离子束的辐照和相关表征技术,提供材料的剖面元素分布、化学组成和晶体结构等信息,有助于研究人员深入了解材料的结构和性能特点。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值