Cesium JS API
AppearanceArcGisMapServerImageryProviderArcGISTiledElevationTerrainProviderArcTypeAssociativeArrayAxisAxisAlignedBoundingBoxbarycentricCoordinatesBillboardBillboardCollectionBillboardGraphicsBillboardVisualizerbinarySearchbinarySearchComparatorBingMapsGeocoderServiceBingMapsImageryProviderBingMapsStyleBlendEquationBlendFunctionBlendingStateBlendOptionBoundingRectangleBoundingSphereBoxEmitterBoxGeometryBoxGeometryUpdaterBoxGraphicsBoxOutlineGeometrybuildModuleUrlCallbackPropertyCameraCameraEventAggregatorCameraEventTypeCartesian2Cartesian3Cartesian4CartographicCartographicGeocoderServiceCatmullRomSplineCesium3DTileCesium3DTileColorBlendModeCesium3DTileContentCesium3DTileFeatureCesium3DTilePointFeatureCesium3DTilesetCesium3DTilesetGraphicsCesium3DTilesetVisualizerCesium3DTileStyleCesium3DTilesVoxelProviderCesiumTerrainProviderCesiumWidgetCheckerboardMaterialPropertyCircleEmitterCircleGeometryCircleOutlineGeometryClassificationPrimitiveClassificationTypeClippingPlaneClippingPlaneCollectionClockClockRangeClockStepcloneCloudCollectionCloudTypeColorColorBlendModeColorGeometryInstanceAttributeColorMaterialPropertycombineComponentDatatypeCompositeEntityCollectionCompositeMaterialPropertyCompositePositionPropertyCompositePropertyCompressedTextureBufferConditionsExpressionConeEmitterConstantPositionPropertyConstantPropertyConstantSplineContextOptionsCoplanarPolygonGeometryCoplanarPolygonOutlineGeometryCornerTypeCorridorGeometryCorridorGeometryUpdaterCorridorGraphicsCorridorOutlineGeometrycreateElevationBandMaterialcreateElevationBandMaterialBandcreateElevationBandMaterialEntrycreateGuidcreateOsmBuildingscreateTangentSpaceDebugPrimitivecreateWorldImagerycreateWorldTerrainCreditCreditDisplayCubicRealPolynomialCullFaceCullingVolumeCumulusCloudCustomDataSourceCustomHeightmapTerrainProviderCustomShaderCustomShaderModeCustomShaderTranslucencyModeCylinderGeometryCylinderGeometryUpdaterCylinderGraphicsCylinderOutlineGeometryCzmlDataSourceDataSourceDataSourceClockDataSourceCollectionDataSourceDisplayDebugAppearanceDebugCameraPrimitiveDebugModelMatrixPrimitiveDefaultProxydefaultValuedefinedDepthFunctiondestroyObjectDeveloperErrorDirectionalLightDirectionUpDiscardEmptyTileImagePolicyDiscardMissingTileImagePolicyDistanceDisplayConditionDistanceDisplayConditionGeometryInstanceAttributeEasingFunctionEllipseGeometryEllipseGeometryUpdaterEllipseGraphicsEllipseOutlineGeometryEllipsoidEllipsoidGeodesicEllipsoidGeometryEllipsoidGeometryUpdaterEllipsoidGraphicsEllipsoidOutlineGeometryEllipsoidRhumbLineEllipsoidSurfaceAppearanceEllipsoidTangentPlaneEllipsoidTerrainProviderEntityEntityClusterEntityCollectionEntityViewEventEventHelperexcludesReverseAxisexportKmlexportKmlModelCallbackexportKmlResultKmlexportKmlResultKmzExpressionExtrapolationTypeFeatureDetectionFogformatErrorFrameRateMonitorFrustumGeometryFrustumOutlineGeometryFullscreenGeocoderServiceGeocodeTypeGeographicProjectionGeographicTilingSchemeGeoJsonDataSourceGeometryGeometryAttributeGeometryAttributesGeometryFactoryGeometryInstanceGeometryInstanceAttributeGeometryPipelineGeometryUpdaterGeometryVisualizergetAbsoluteUrigetBaseUrigetExtensionFromUriGetFeatureInfoFormatgetFilenameFromUrigetImagePixelsgetTimestampGlobeGlobeTranslucencyGoogleEarthEnterpriseImageryProviderGoogleEarthEnterpriseMapsProviderGoogleEarthEnterpriseMetadataGoogleEarthEnterpriseTerrainDataGoogleEarthEnterpriseTerrainProviderGpxDataSourceGregorianDateGridImageryProviderGridMaterialPropertyGroundGeometryUpdaterGroundPolylineGeometryGroundPolylinePrimitiveGroundPrimitiveHeadingPitchRangeHeadingPitchRollHeadingPitchRollValuesHeightmapEncodingHeightmapTerrainDataHeightReferenceHermitePolynomialApproximationHermiteSplineHilbertOrderHorizontalOriginI3SDataProviderI3SFeatureI3SFieldI3SGeometryI3SLayerI3SNodeImageBasedLightingImageMaterialPropertyImageryLayerImageryLayerCollectionImageryLayerFeatureInfoImageryProviderImageryTypesincludesReverseAxisIndexDatatypeIntersectIntersections2DIntersectionTestsIntervalIonIonGeocoderServiceIonImageryProviderIonResourceIonWorldImageryStyleisLeapYearIso8601JulianDateKeyboardEventModifierKmlCameraKmlDataSourceKmlFeatureDataKmlLookAtKmlTourKmlTourFlyToKmlTourWaitLabelLabelCollectionLabelGraphicsLabelStyleLabelVisualizerLagrangePolynomialApproximationLeapSecondLightLightingModelLinearApproximationLinearSplineMapboxImageryProviderMapboxStyleImageryProviderMapMode2DMapProjectionMaterialMaterialAppearanceMaterialSupportMaterialPropertyMathMatrix2Matrix3Matrix4mergeSortmergeSortComparatorMetadataClassMetadataClassPropertyMetadataComponentTypeMetadataEnumMetadataEnumValueMetadataSchemaMetadataTypeModelModelAnimationModelAnimationCollectionModelAnimationLoopModelFeatureModelGraphicsModelNodeModelVisualizerMoonMorphWeightSplineNearFarScalarNeverTileDiscardPolicyNodeTransformationPropertyobjectToQueryOccluderOpenCageGeocoderServiceOpenStreetMapImageryProviderOrientedBoundingBoxOrthographicFrustumOrthographicOffCenterFrustumPackableForInterpolationParticleParticleBurstParticleEmitterParticleSystemPathGraphicsPathVisualizerPeliasGeocoderServicePerInstanceColorAppearancePerspectiveFrustumPerspectiveOffCenterFrustumPinBuilderPixelDatatypePixelFormatPlanePlaneGeometryPlaneGeometryUpdaterPlaneGraphicsPlaneOutlineGeometryPointCloudShadingPointGraphicspointInsideTrianglePointPrimitivePointPrimitiveCollectionPointVisualizerPolygonGeometryPolygonGeometryUpdaterPolygonGraphicsPolygonHierarchyPolygonOutlineGeometryPolylinePolylineArrowMaterialPropertyPolylineCollectionPolylineColorAppearancePolylineDashMaterialPropertyPolylineGeometryPolylineGeometryUpdaterPolylineGlowMaterialPropertyPolylineGraphicsPolylineMaterialAppearancePolylineOutlineMaterialPropertyPolylineVisualizerPolylineVolumeGeometryPolylineVolumeGeometryUpdaterPolylineVolumeGraphicsPolylineVolumeOutlineGeometryPositionPropertyPositionPropertyArrayPostProcessStagePostProcessStageCollectionPostProcessStageCompositePostProcessStageLibraryPostProcessStageSampleModePrimitivePrimitiveCollectionPrimitiveTypePropertyPropertyArrayPropertyBagProxyQuadraticRealPolynomialQuantizedMeshTerrainDataQuarticRealPolynomialQuaternionQuaternionSplinequeryToObjectQueueRayreadyPromiseRectangleRectangleGeometryRectangleGeometryUpdaterRectangleGraphicsRectangleOutlineGeometryReferenceFrameReferencePropertyremoveExtensionRequestRequestErrorEventRequestSchedulerRequestStateRequestTypeResourceRuntimeErrorSampledPositionPropertySampledPropertysampleTerrainsampleTerrainMostDetailedSceneSceneModeSceneTransformsScreenSpaceCameraControllerScreenSpaceEventHandlerScreenSpaceEventTypeshaderDefinesshaderMaximumIntersectionsLengthshaderUniformsShadowMapShadowModeShowGeometryInstanceAttributeSimon1994PlanetaryPositionsSimplePolylineGeometrySingleTileImageryProviderSkyAtmosphereSkyBoxSphereEmitterSphereGeometrySphereOutlineGeometrySphericalSplineSplitDirectionStencilFunctionStencilOperationSteppedSplineStripeMaterialPropertyStripeOrientationStyleExpressionsubdivideArraySunSunLightTaskProcessorTerrainDataTerrainProviderTextureMagnificationFilterTextureMinificationFilterTextureUniformTileAvailabilityTileCoordinatesImageryProviderTileDiscardPolicyTileMapServiceImageryProviderTileProviderErrorTilingSchemeTimeDynamicImageryTimeDynamicPointCloudTimeIntervalTimeIntervalCollectionTimeIntervalCollectionPositionPropertyTimeIntervalCollectionPropertyTimeStandardTransformsTranslationRotationScaleTridiagonalSystemSolverTrustedServersUniformSpecifierUniformTypeUrlTemplateImageryProviderVaryingTypeVelocityOrientationPropertyVelocityVectorPropertyVertexFormatVerticalOriginVideoSynchronizerViewportQuadVisibilityVisualizerVoxelPrimitiveVoxelProviderVoxelShapeTypeVRTheWorldTerrainProviderWallGeometryWallGeometryUpdaterWallGraphicsWallOutlineGeometryWebGLConstantsWebGLOptionsWebMapServiceImageryProviderWebMapTileServiceImageryProviderWebMercatorProjectionWebMercatorTilingSchemeWindingOrderwriteTextToCanvasAnimationAnimationViewModelBaseLayerPickerBaseLayerPickerViewModelCesium3DTilesInspectorCesium3DTilesInspectorViewModelCesiumInspectorCesiumInspectorViewModelClockViewModelCommandcreateCommandFullscreenButtonFullscreenButtonViewModelGeocoderGeocoderViewModelHomeButtonHomeButtonViewModelInfoBoxInfoBoxViewModelNavigationHelpButtonNavigationHelpButtonViewModelPerformanceWatchdogPerformanceWatchdogViewModelProjectionPickerProjectionPickerViewModelProviderViewModelSceneModePickerSceneModePickerViewModelSelectionIndicatorSelectionIndicatorViewModelSvgPathBindingHandlerTimelineToggleButtonViewModelViewerviewerCesium3DTilesInspectorMixinviewerCesiumInspectorMixinviewerDragDropMixinviewerPerformanceWatchdogMixinviewerVoxelInspectorMixinVoxelInspectorVoxelInspectorViewModelVRButtonVRButtonViewModel

IntersectionTests

IntersectionTests(交叉测试)是CesiumJS的一个模块,提供了检测和计算三维空间中各种复杂结构几何形状之间的相交性的功能。这个模块包括多个函数和类,可以用于识别线段、射线、平面、椭球体、圆柱体、盒子等物体之间的相交情况。

函数

rayPlane(ray, plane, result)

检测射线(ray)和平面(plane)是否有交点,若有,返回交点坐标(result),否则返回undefined

rayEllipsoid(ray, ellipsoid, result)

检测射线(ray)和椭球体(ellipsoid)是否有交点,若有,返回交点坐标(result),否则返回undefined

raySphere(ray, sphere, result)

检测射线(ray)和球体(sphere)是否有交点,若有,返回交点坐标(result),否则返回undefined

segmentPlane(start, end, plane, result)

检测线段(start到end)和平面(plane)是否有交点,若有,返回交点坐标(result),否则返回undefined

rayTriangle(ray, p0, p1, p2, cullBackFaces)

检测射线(ray)和三角形(p0、p1、p2构成的三角形)是否有交点,若有,返回交点距离,否则返回undefined

lineSegmentPlane(start0, end0, start1, end1, result)

检测线段(start0到end0)和平面(由start1和end1确定)是否有交点,若有,返回交点坐标(result),否则返回undefined

lineSegmentTriangle(p0, p1, p2, endPoint0, endPoint1, cullBackFaces)

检测线段(endPoint0到endPoint1)和三角形(p0、p1、p2构成的三角形)是否有交点,若有,返回交点距离,否则返回undefined

trianglePlaneIntersection(p0, p1, p2, plane, result)

检测三角形(p0、p1、p2构成的三角形)和平面(plane)是否有交点,若有,返回交点坐标(result),否则返回undefined

rayEllipsoidIntersectionInterval(ray, ellipsoid)

检测射线(ray)和椭球体(ellipsoid)是否有交点,若有,返回交点距离的范围(最小和最大距离),否则返回undefined

raySphereIntersectionInterval(ray, sphere)

检测射线(ray)和球体(sphere)是否有交点,若有,返回交点距离的范围(最小和最大距离),否则返回undefined

segmentSphereIntersection(start, end, sphere, result)

检测线段(start到end)和球体(sphere)是否有交点,若有,返回交点坐标(result),否则返回undefined

rayRectangleIntersection(ray, rectangle)

检测射线(ray)是否穿过二维矩形空间(rectangle)内部,若有,返回穿过矩形面的交点坐标。

Interval

表示距离的一个区间,包括最小和最大距离。可以通过isEmptycontains等函数进行区间的基本运算。

Plane

表示三维空间内的一个平面,可以通过法线向量和交点坐标两种方式进行定义,可以进行点到平面距离等运算。

Ellipsoid

表示三维空间内的一个椭球体,可以通过中心坐标和三个轴长进行定义,可以进行点到表面距离等运算。

Sphere

表示三维空间内的一个球体,可以通过中心坐标和半径进行定义,可以进行点到表面距离等运算。

Triangle

表示三维空间内的一个三角形,可以通过三个顶点坐标进行定义,可以进行内部点判定等运算。

OrientedBoundingBox

表示三维空间内的一个定向盒子,可以通过中心坐标、半径、旋转角度进行定义,可以进行点到表面距离等运算。

使用示例


import { Cartographic, Ellipsoid, EllipsoidGeodesic, Math, Ray, Cartesian3 } from 'cesium';

// 计算两点间的大圆弧路径所覆盖的椭球体面积
function computeSurfaceArea(start, end) {
  const ellipsoid = Ellipsoid.WGS84;
  const geodesic = new EllipsoidGeodesic(start, end, ellipsoid);
  const numIntervals = 16; // 等分数
  let areaTotal = 0;
  let i;
  for (i = 0; i < numIntervals; i++) {
    const intervalStart = geodesic.interpolateUsingSurfaceDistance(i / numIntervals);
    const intervalEnd = geodesic.interpolateUsingSurfaceDistance((i + 1) / numIntervals);
    const triangles = ellipsoid.computeTriangleStrip(intervalStart, intervalEnd);
    for (let j = 0; j < triangles.length; j += 3) {
      const p0 = triangles[j];
      const p1 = triangles[j + 1];
      const p2 = triangles[j + 2];
      areaTotal += computeTriangleArea(p0, p1, p2);
    }
  }
  return areaTotal;
}

// 计算三角形面积
function computeTriangleArea(p0, p1, p2) {
  const vector1 = Cartesian3.subtract(p1, p0, new Cartesian3());
  const vector2 = Cartesian3.subtract(p2, p0, new Cartesian3());
  const crossProduct = Cartesian3.cross(vector1, vector2, new Cartesian3());
  return 0.5 * Cartesian3.magnitude(crossProduct);
}

// 判断射线是否和二维矩形相交
function isRayIntersectRectangle(ray, rectangle) {
  const intersectionPoint = new Cartesian3();
  const intersection = IntersectionTests.rayRectangleIntersection(ray, rectangle, intersectionPoint);
  return typeof intersection !== 'undefined';
}

// 判断线段是否和平面相交
function isSegmentIntersectPlane(start, end, plane) {
  const intersectionPoint = new Cartesian3();
  const intersection = IntersectionTests.segmentPlane(start, end, plane, intersectionPoint);
  return typeof intersection !== 'undefined';
}

以上是IntersectionTests模块的简单介绍和使用示例,更多详细内容可参考CesiumJS官方文档。