Cesium JS API
AppearanceArcGisMapServerImageryProviderArcGISTiledElevationTerrainProviderArcTypeAssociativeArrayAxisAxisAlignedBoundingBoxbarycentricCoordinatesBillboardBillboardCollectionBillboardGraphicsBillboardVisualizerbinarySearchbinarySearchComparatorBingMapsGeocoderServiceBingMapsImageryProviderBingMapsStyleBlendEquationBlendFunctionBlendingStateBlendOptionBoundingRectangleBoundingSphereBoxEmitterBoxGeometryBoxGeometryUpdaterBoxGraphicsBoxOutlineGeometrybuildModuleUrlCallbackPropertyCameraCameraEventAggregatorCameraEventTypeCartesian2Cartesian3Cartesian4CartographicCartographicGeocoderServiceCatmullRomSplineCesium3DTileCesium3DTileColorBlendModeCesium3DTileContentCesium3DTileFeatureCesium3DTilePointFeatureCesium3DTilesetCesium3DTilesetGraphicsCesium3DTilesetVisualizerCesium3DTileStyleCesium3DTilesVoxelProviderCesiumTerrainProviderCesiumWidgetCheckerboardMaterialPropertyCircleEmitterCircleGeometryCircleOutlineGeometryClassificationPrimitiveClassificationTypeClippingPlaneClippingPlaneCollectionClockClockRangeClockStepcloneCloudCollectionCloudTypeColorColorBlendModeColorGeometryInstanceAttributeColorMaterialPropertycombineComponentDatatypeCompositeEntityCollectionCompositeMaterialPropertyCompositePositionPropertyCompositePropertyCompressedTextureBufferConditionsExpressionConeEmitterConstantPositionPropertyConstantPropertyConstantSplineContextOptionsCoplanarPolygonGeometryCoplanarPolygonOutlineGeometryCornerTypeCorridorGeometryCorridorGeometryUpdaterCorridorGraphicsCorridorOutlineGeometrycreateElevationBandMaterialcreateElevationBandMaterialBandcreateElevationBandMaterialEntrycreateGuidcreateOsmBuildingscreateTangentSpaceDebugPrimitivecreateWorldImagerycreateWorldTerrainCreditCreditDisplayCubicRealPolynomialCullFaceCullingVolumeCumulusCloudCustomDataSourceCustomHeightmapTerrainProviderCustomShaderCustomShaderModeCustomShaderTranslucencyModeCylinderGeometryCylinderGeometryUpdaterCylinderGraphicsCylinderOutlineGeometryCzmlDataSourceDataSourceDataSourceClockDataSourceCollectionDataSourceDisplayDebugAppearanceDebugCameraPrimitiveDebugModelMatrixPrimitiveDefaultProxydefaultValuedefinedDepthFunctiondestroyObjectDeveloperErrorDirectionalLightDirectionUpDiscardEmptyTileImagePolicyDiscardMissingTileImagePolicyDistanceDisplayConditionDistanceDisplayConditionGeometryInstanceAttributeEasingFunctionEllipseGeometryEllipseGeometryUpdaterEllipseGraphicsEllipseOutlineGeometryEllipsoidEllipsoidGeodesicEllipsoidGeometryEllipsoidGeometryUpdaterEllipsoidGraphicsEllipsoidOutlineGeometryEllipsoidRhumbLineEllipsoidSurfaceAppearanceEllipsoidTangentPlaneEllipsoidTerrainProviderEntityEntityClusterEntityCollectionEntityViewEventEventHelperexcludesReverseAxisexportKmlexportKmlModelCallbackexportKmlResultKmlexportKmlResultKmzExpressionExtrapolationTypeFeatureDetectionFogformatErrorFrameRateMonitorFrustumGeometryFrustumOutlineGeometryFullscreenGeocoderServiceGeocodeTypeGeographicProjectionGeographicTilingSchemeGeoJsonDataSourceGeometryGeometryAttributeGeometryAttributesGeometryFactoryGeometryInstanceGeometryInstanceAttributeGeometryPipelineGeometryUpdaterGeometryVisualizergetAbsoluteUrigetBaseUrigetExtensionFromUriGetFeatureInfoFormatgetFilenameFromUrigetImagePixelsgetTimestampGlobeGlobeTranslucencyGoogleEarthEnterpriseImageryProviderGoogleEarthEnterpriseMapsProviderGoogleEarthEnterpriseMetadataGoogleEarthEnterpriseTerrainDataGoogleEarthEnterpriseTerrainProviderGpxDataSourceGregorianDateGridImageryProviderGridMaterialPropertyGroundGeometryUpdaterGroundPolylineGeometryGroundPolylinePrimitiveGroundPrimitiveHeadingPitchRangeHeadingPitchRollHeadingPitchRollValuesHeightmapEncodingHeightmapTerrainDataHeightReferenceHermitePolynomialApproximationHermiteSplineHilbertOrderHorizontalOriginI3SDataProviderI3SFeatureI3SFieldI3SGeometryI3SLayerI3SNodeImageBasedLightingImageMaterialPropertyImageryLayerImageryLayerCollectionImageryLayerFeatureInfoImageryProviderImageryTypesincludesReverseAxisIndexDatatypeIntersectIntersections2DIntersectionTestsIntervalIonIonGeocoderServiceIonImageryProviderIonResourceIonWorldImageryStyleisLeapYearIso8601JulianDateKeyboardEventModifierKmlCameraKmlDataSourceKmlFeatureDataKmlLookAtKmlTourKmlTourFlyToKmlTourWaitLabelLabelCollectionLabelGraphicsLabelStyleLabelVisualizerLagrangePolynomialApproximationLeapSecondLightLightingModelLinearApproximationLinearSplineMapboxImageryProviderMapboxStyleImageryProviderMapMode2DMapProjectionMaterialMaterialAppearanceMaterialSupportMaterialPropertyMathMatrix2Matrix3Matrix4mergeSortmergeSortComparatorMetadataClassMetadataClassPropertyMetadataComponentTypeMetadataEnumMetadataEnumValueMetadataSchemaMetadataTypeModelModelAnimationModelAnimationCollectionModelAnimationLoopModelFeatureModelGraphicsModelNodeModelVisualizerMoonMorphWeightSplineNearFarScalarNeverTileDiscardPolicyNodeTransformationPropertyobjectToQueryOccluderOpenCageGeocoderServiceOpenStreetMapImageryProviderOrientedBoundingBoxOrthographicFrustumOrthographicOffCenterFrustumPackableForInterpolationParticleParticleBurstParticleEmitterParticleSystemPathGraphicsPathVisualizerPeliasGeocoderServicePerInstanceColorAppearancePerspectiveFrustumPerspectiveOffCenterFrustumPinBuilderPixelDatatypePixelFormatPlanePlaneGeometryPlaneGeometryUpdaterPlaneGraphicsPlaneOutlineGeometryPointCloudShadingPointGraphicspointInsideTrianglePointPrimitivePointPrimitiveCollectionPointVisualizerPolygonGeometryPolygonGeometryUpdaterPolygonGraphicsPolygonHierarchyPolygonOutlineGeometryPolylinePolylineArrowMaterialPropertyPolylineCollectionPolylineColorAppearancePolylineDashMaterialPropertyPolylineGeometryPolylineGeometryUpdaterPolylineGlowMaterialPropertyPolylineGraphicsPolylineMaterialAppearancePolylineOutlineMaterialPropertyPolylineVisualizerPolylineVolumeGeometryPolylineVolumeGeometryUpdaterPolylineVolumeGraphicsPolylineVolumeOutlineGeometryPositionPropertyPositionPropertyArrayPostProcessStagePostProcessStageCollectionPostProcessStageCompositePostProcessStageLibraryPostProcessStageSampleModePrimitivePrimitiveCollectionPrimitiveTypePropertyPropertyArrayPropertyBagProxyQuadraticRealPolynomialQuantizedMeshTerrainDataQuarticRealPolynomialQuaternionQuaternionSplinequeryToObjectQueueRayreadyPromiseRectangleRectangleGeometryRectangleGeometryUpdaterRectangleGraphicsRectangleOutlineGeometryReferenceFrameReferencePropertyremoveExtensionRequestRequestErrorEventRequestSchedulerRequestStateRequestTypeResourceRuntimeErrorSampledPositionPropertySampledPropertysampleTerrainsampleTerrainMostDetailedSceneSceneModeSceneTransformsScreenSpaceCameraControllerScreenSpaceEventHandlerScreenSpaceEventTypeshaderDefinesshaderMaximumIntersectionsLengthshaderUniformsShadowMapShadowModeShowGeometryInstanceAttributeSimon1994PlanetaryPositionsSimplePolylineGeometrySingleTileImageryProviderSkyAtmosphereSkyBoxSphereEmitterSphereGeometrySphereOutlineGeometrySphericalSplineSplitDirectionStencilFunctionStencilOperationSteppedSplineStripeMaterialPropertyStripeOrientationStyleExpressionsubdivideArraySunSunLightTaskProcessorTerrainDataTerrainProviderTextureMagnificationFilterTextureMinificationFilterTextureUniformTileAvailabilityTileCoordinatesImageryProviderTileDiscardPolicyTileMapServiceImageryProviderTileProviderErrorTilingSchemeTimeDynamicImageryTimeDynamicPointCloudTimeIntervalTimeIntervalCollectionTimeIntervalCollectionPositionPropertyTimeIntervalCollectionPropertyTimeStandardTransformsTranslationRotationScaleTridiagonalSystemSolverTrustedServersUniformSpecifierUniformTypeUrlTemplateImageryProviderVaryingTypeVelocityOrientationPropertyVelocityVectorPropertyVertexFormatVerticalOriginVideoSynchronizerViewportQuadVisibilityVisualizerVoxelPrimitiveVoxelProviderVoxelShapeTypeVRTheWorldTerrainProviderWallGeometryWallGeometryUpdaterWallGraphicsWallOutlineGeometryWebGLConstantsWebGLOptionsWebMapServiceImageryProviderWebMapTileServiceImageryProviderWebMercatorProjectionWebMercatorTilingSchemeWindingOrderwriteTextToCanvasAnimationAnimationViewModelBaseLayerPickerBaseLayerPickerViewModelCesium3DTilesInspectorCesium3DTilesInspectorViewModelCesiumInspectorCesiumInspectorViewModelClockViewModelCommandcreateCommandFullscreenButtonFullscreenButtonViewModelGeocoderGeocoderViewModelHomeButtonHomeButtonViewModelInfoBoxInfoBoxViewModelNavigationHelpButtonNavigationHelpButtonViewModelPerformanceWatchdogPerformanceWatchdogViewModelProjectionPickerProjectionPickerViewModelProviderViewModelSceneModePickerSceneModePickerViewModelSelectionIndicatorSelectionIndicatorViewModelSvgPathBindingHandlerTimelineToggleButtonViewModelViewerviewerCesium3DTilesInspectorMixinviewerCesiumInspectorMixinviewerDragDropMixinviewerPerformanceWatchdogMixinviewerVoxelInspectorMixinVoxelInspectorVoxelInspectorViewModelVRButtonVRButtonViewModel

埃尔米特样条

本文将介绍在CesiumJS中的HermiteSpline类及其使用方法。

什么是埃尔米特样条?

埃尔米特样条是一种参数化的光滑曲线,由Hermann Hankel和Charles Hermite独立提出。它是一组相邻点间光滑曲线段的集合,其中每一条曲线段都由两个相邻点的位置和方向确定。

埃尔米特样条的曲线段较短,具有良好的插值性能。此外,由于可以在每个点处设置曲率,因此它还具有良好的完美性能。

在CesiumJS中的HermiteSpline

CesiumJS的HermiteSpline类是一个javascript类,可用于创建埃尔米特样条。其构造函数如下所示:

HermiteSpline(points, times, inTangents, outTangents)

其中,四个参数的含义如下所示:

  • points:一个数组,由x,y和z坐标值表示的联合量,表示埃尔米特样条曲线的控制点。

  • times:一个与点数相同的数组,表示每个点在曲线上的时间。

  • inTangents:与点数相同的另一个数组,表示每个点的入方向。

  • outTangents:与点数相同的另一个数组,表示每个点的出方向。

HermiteSpline实例还具有以下方法:

  • evaluate(time, result):计算在指定时间的曲线上的点,并将结果存储在result中。

  • getPoint(index, result):获取曲线中指定索引的点,并将结果存储在result中。

  • getTangent(index, result):获取曲线中指定索引的方向,并将结果存储在result中。

  • times:点在曲线上的时间数组。

  • length:曲线的总长度。

示例

下面是一个简单的例子,展示了如何在CesiumJS中创建一个埃尔米特样条:

// 定义点和两个向量
var points = [
   new Cesium.Cartesian3(0.0, 0.0, 0.0),
   new Cesium.Cartesian3(2.0, 3.0, 5.0),
   new Cesium.Cartesian3(4.0, 2.0, 6.0),
   new Cesium.Cartesian3(7.0, 1.0, 3.0),
   new Cesium.Cartesian3(8.0, 0.0, 1.0)
];

var inTangents = [
   new Cesium.Cartesian3(1.0, 0.0, 0.0),
   new Cesium.Cartesian3(-5.0, 1.0, -2.0),
   new Cesium.Cartesian3(-2.0, -5.0, 3.0),
   new Cesium.Cartesian3(1.0, 2.0, 2.0),
   new Cesium.Cartesian3(-1.0, 1.0, -1.0)
];

var outTangents = [
   new Cesium.Cartesian3(1.0, -3.0, 2.0),
   new Cesium.Cartesian3(1.0, 0.0, 1.0),
   new Cesium.Cartesian3(0.0, -1.0, 4.0),
   new Cesium.Cartesian3(3.0, 3.0, -2.0),
   new Cesium.Cartesian3(1.0, -1.0, 2.0)
];

// 创建已定曲线
var curve = new Cesium.HermiteSpline(points, [0, 1, 2, 3, 4], inTangents, outTangents);

此外,我们还可以在地球上绘制埃尔米特样条。下面是一个例子,展示了如何在CesiumJS中实现:

// 创建点列表
var points = [
   new Cesium.Cartesian3(0.0, 0.0, 0.0),
   new Cesium.Cartesian3(1000000.0, 1000000.0, 1000000.0),
   new Cesium.Cartesian3(-1000000.0, -1000000.0, -1000000.0),
   new Cesium.Cartesian3(0.0, 0.0, 0.0)
];

// 创建入向量和出向量列表
var inTangents = [
   new Cesium.Cartesian3(0.0, 0.0, -1000000.0),
   new Cesium.Cartesian3(0.0, -1000000.0, 0.0),
   new Cesium.Cartesian3(-1000000.0, 0.0, 0.0),
   new Cesium.Cartesian3(0.0, 0.0, 1000000.0)
];

var outTangents = [
   new Cesium.Cartesian3(0.0, 1000000.0, 0.0),
   new Cesium.Cartesian3(1000000.0, 0.0, 0.0),
   new Cesium.Cartesian3(0.0, 0.0, -1000000.0),
   new Cesium.Cartesian3(-1000000.0, -1000000.0, -1000000.0)
];

// 创建已定曲线
var curve = new Cesium.HermiteSpline(points, [0, 1, 2, 3], inTangents, outTangents);

// 创建路径样式
var pathMaterial = new Cesium.PolylineGlowMaterialProperty({
   glowPower : 0.2,
   color : Cesium.Color.YELLOW
});

// 创建路径实例
var pathInstance = new Cesium.GeometryInstance({
   geometry : new Cesium.PolylineGeometry({
       positions : curve.positions,
       colors : curve.colors,
       widths : [10.0, 40.0, 20.0, 1.0]
   }),
   id : 'path',
   attributes : {
       color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.YELLOW)
   },
   material : pathMaterial,
   show : true,
   onlyAllowTranslucency : true
});

// 添加到场景
viewer.scene.primitives.add(new Cesium.Primitive({
   geometryInstances : [pathInstance],
   appearance : new Cesium.PerInstanceColorAppearance({
       flat : true,
       translucent : false
   })
}));

当我们执行这段代码后,将在地球上绘制黄色路径。

总结

本文介绍了在CesiumJS中的HermiteSpline类及其使用方法,包括构造函数和实例方法。此外,我们还提供了一些代码示例,帮助您更好地理解如何在CesiumJS中使用埃尔米特样条。