在Cesium开发中需要获取线段【line Segment】与地面三角形【Triangle】三条边的交点,查阅官方API文档说明,发现Cesium框架提供了 Cesium.IntersectionTests.lineSegmentTriangle()功能函数。但是在使用中无法获取交点。
被此问题困扰了两天,今天想到可能因为地球是个球体,所以贴地面是弧面,导致水平线段,不能与三角面相交。所以此处在三角面的三条边处,分别绘制垂直于地球平面的竖立着的三角面,分别求其交点,最终获取到了梦寐以求的交点处经纬度。
var IntersectionList = [];
var IntersectionPoint = Cesium.IntersectionTests.lineSegmentTriangle(log_point1, log_point2, pois_no_hei[0], pois_no_hei[1], pois_hei[0], false);
if(IntersectionPoint != null)
{
IntersectionList.push(IntersectionPoint);
// console.log(IntersectionPoint);
}
IntersectionPoint = Cesium.IntersectionTests.lineSegmentTriangle(log_point1, log_point2, pois_no_hei[1], pois_no_hei[2], pois_hei[1], false);
if(IntersectionPoint != null)
{
IntersectionList.push(IntersectionPoint);
// console.log(IntersectionPoint);
}
IntersectionPoint = Cesium.IntersectionTests.lineSegmentTriangle(log_point1, log_point2, pois_no_hei[0], pois_no_hei[2], pois_hei[2], false);
if(IntersectionPoint != null)
{
IntersectionList.push(IntersectionPoint);
// console.log(IntersectionPoint);
}