Most Used CSPICE APIs |
CSPICE APIs for accessing SPICE kernel data
CSPICE APIs for computing derived geometry
CSPICE APIs for checking geometric conditionsCSPICE APIs for finding times of geometric events
CSPICE APIs for coordinate conversions
CSPICE APIs for operations with 3D vectors and matrices
Miscellaneous CSPICE APIsLoading and Unloading SPICE KernelsAPIs:
Brief Example:Generic LSK and PCK files listed in a meta-kernel named "mykernels.furnsh" and containing \begindata KERNELS_TO_LOAD = ( '/kernels/gen/lsk/naif0008.tls' '/kernels/gen/pck/pck00008.tps' ) \begintext are loaded with a single call to furnsh_c: furnsh_c ( "mykernels.furnsh" ); Reference documents:
Converting between UTC and Ephemeris Time (LSK)APIs:
Brief Example:The following example loads an LSK file, converts a UTC string to ET seconds, adds 1 day and converts TDB seconds back to a UTC string in ISO DOY format: SpiceDouble et; SpiceChar utc[32]; /* load LSK file */ furnsh_c ( "naif0008.tls" ); /* convert UTC to ET */ str2et_c ( "2005 DEC 31 12:00", &et ); /* add 1 day to ET and convert it back to UTC */ timout_c ( et+spd_c(), "YYYY-DOYTHR:MN:SC.### ::RND", 32, utc ); Reference documents:
Converting between Ephemeris Time and Spacecraft Clock (SCLK)APIs:
Brief Example:The following example loads an LSK file and an MGS SCLK file, then converts an MGS SCLK string to ET and encoded SCLK: SpiceChar * sclk; SpiceDouble et; SpiceDouble sclkdp; SpiceInt scid = -94; /* load LSK and SCLK files */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "mgs_sclkscet_00061.tsc" ); /* convert string SCLK to ET and to encoded SCLK */ sclk = "820584056:121"; scs2e_c ( scid, sclk, &et ); scencd_c ( scid, sclk, &sclkdp ); Reference documents:
Constants and Orientation for Natural Bodies (PCK)APIs:
Brief Example:The following example retrieves radii for Mars and computes orientation of the Mars body-fixed frame: SpiceDouble et; SpiceDouble mat[3][3]; SpiceDouble radii[3]; SpiceInt n; /* load LSK and PCK files */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "pck00008.tpc" ); /* retrieve Mars radii */ bodvrd_c ( "MARS", "RADII", 3, &n, radii ); /* convert UTC to ET */ str2et_c ( "2005-DEC-28 12:00", &et ); /* compute Mars orientation relative to the J2000 frame */ pxform_c ( "J2000", "IAU_MARS", et, mat ); Reference documents:
Computing Transformations Between Frames (FK)APIs:
Brief Example:The following example computes orientation of the CASSINI ISS WAC camera relative to the Saturn body-fixed frame: SpiceDouble et; SpiceDouble mat[3][3]; /* load kernels: LSK, PCK, CASSINI SCLK, FK and CK */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "pck00008.tpc" ); furnsh_c ( "cas00101.tsc" ); furnsh_c ( "cas_v39.tf" ); furnsh_c ( "05362_06002ra.bc" ); /* convert UTC to ET */ str2et_c ( "2005-DEC-28 12:00", &et ); /* compute orientation of CASSINI relative to J2000 frame */ pxform_c ( "IAU_SATURN", "CASSINI_ISS_WAC", et, mat ); Reference documents:
Computing Positions of Spacecraft and Natural Bodies (SPK)APIs:
Brief Example:The following example computes the geometric state (position and velocity) of MGS relative to Mars in the J2000 reference frame: SpiceDouble et; SpiceDouble state[6]; SpiceDouble lt; /* load kernels: LSK and MGS and DE SPKs */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "de405.bsp" ); furnsh_c ( "mgs_ext22.bsp" ); /* convert UTC to ET */ str2et_c ( "2006 JAN 31 01:00", &et ); /* compute geometric state of MGS relative to Mars */ spkezr_c ( "MGS", et, "J2000", "NONE", "MARS", state, < ); Reference documents:
Computing Orientation for Spacecraft and Instruments (CK)APIs:
Brief Example:The following example computes orientation of the CASSINI spacecraft provided in CK files using the Frames subsystem routine pxform_c: SpiceDouble et; SpiceDouble mat[3][3]; /* load kernels: LSK, CASSINI SCLK, FK and CK */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "cas00101.tsc" ); furnsh_c ( "cas_v39.tf" ); furnsh_c ( "05362_06002ra.bc" ); /* convert UTC to ET */ str2et_c ( "2005-DEC-28 12:00", &et ); /* compute orientation of CASSINI relative to J2000 frame */ pxform_c ( "J2000", "CASSINI_SC_COORD", et, mat ); Reference documents:
Retrieving Instrument Parameters (IK)APIs:
Brief Example:The following example retrieves the M01 THEMIS IR camera focal length and FOV parameters: SpiceBoolean found; SpiceChar frame[32]; SpiceChar shape[32]; SpiceDouble fl; SpiceDouble bsight[3]; SpiceDouble bounds[4][3]; SpiceInt n; /* load M01 FK and THEMIS IK */ furnsh_c ( "m01_v28.tf" ); furnsh_c ( "m01_themis_v32.ti" ); /* retrieve M01 THEMIS IR pixel size */ gdpool_c ( "INS-53031_FOCAL_LENGTH", 0, 1, &n, &fl, &found ); /* retrieve M01 THEMIS IR FOV parameters */ getfvn_c ( "M01_THEMIS_IR", 4, 32, 32, shape, frame, bsight, &n, bounds ); Reference documents:
Computing surface coordinates using digital shape (DSK)APIs:
Brief Example:The following example computes surface points and normals for for a one-degree longitude/latitude grid on Phobos modeled by a DSK: SpiceInt n; SpiceInt i; SpiceInt j; SpiceDouble grid [360*179][2]; SpiceDouble srfpts [360*179][3]; SpiceDouble normls [360*179][3]; /* Load generic PCK and Phobos DSK. */ furnsh_c ( "pck00010.tpc" ); furnsh_c ( "phobos512.bds" ); /* Generate longitude/latitude pairs of the grid (without poles). */ n = 0; for ( i = 1; i <= 360; i++ ) { for ( j = 1; j <= 179; j++ ) { grid[n][0] = rpd_c() * i; grid[n][1] = rpd_c() * ( j - 90 ); ++n; } } /* Compute surface points based on DSK. */ latsrf_c ( "DSK/UNPRIORITIZED", "PHOBOS", 0.0, "IAU_PHOBOS", n, grid, srfpts ); /* Compute surface normals based on DSK. */ srfnrm_c ( "DSK/UNPRIORITIZED", "PHOBOS", 0.0, "IAU_PHOBOS", n, srfpts, normls ); Reference documents:
Mapping Between Object Names and NAIF IDsAPIs:
Brief Example:The following example uses bodn2c_c to get the NAIF ID for Phobos (built into the SPICE system) and for the M01 THEMIS IR camera (defined in the M01 FK file): SpiceBoolean found; Spiceint phobos_id; Spiceint themis_ir_id; /* load FK defining M01 name-ID mappings */ furnsh_c ( "m01_v28.tf" ); /* get NAIF ID for Phobos */ bodn2c_c ( "PHOBOS", &phobos_id, &found ); /* get NAIF ID for THEMIS IR camera */ bodn2c_c ( "M01_THEMIS_IR", &themis_ir_id, &found ); Reference documents:
Mapping objects to their preferred reference framesAPIs:
Brief Example:The following example loads a text kernel that sets the preferred reference frame for the Earth to 'ITRF93' and calls cnmfrm_c to retrieve the name of this frame: SpiceInt frcode; SpiceChar frname[32]; SpiceBoolean found; /* load FK associating 'ITRF93' with the Earth */ furnsh_c ( "earth_assoc_itrf93.tf" ); /* retrieve the name of the preferred frame for the Earth */ cnmfrm_c ( "EARTH", 32, &frcode, frname, &found ); Reference documents:
Mapping between surface names and NAIF IDsAPIs:
Brief Example:The following example uses srfs2c_c to get the surface ID for the 67P/Churyumov-Gerasimenko DSK surface named "ROS_CG_M001_OMSDLAM_N_V1": SpiceInt surfid; SpiceBoolean found; /* Load ROS FK defining surface name-ID mappings */ furnsh_c ( "ROS_V25.TF" ); /* Get NAIF ID for the surface "ROS_CG_M001_OMSDLAM_N_V1" */ srfs2c_c ( "ROS_CG_M001_OMSDLAM_N_V1", "67P/C-G", &surfid, &found ); Reference documents:
Computing Planetocentric, Planetodetic, and Planetographic CoordinatesAPIs:
Brief Example:The following example computes the planetocentric, planetodetic and planetographic coordinates for a point given as a Cartesian vector with respect to Mars in the Mars body-fixed frame (IAU_MARS): SpiceDouble vec[3]; SpiceDouble radii[3]; SpiceDouble f; SpiceDouble pcr, pclon, pclat; SpiceDouble pdalt, pdlon, pdlat; SpiceDouble pgalt, pglon, pglat; SpiceInt n; /* load PCK file */ furnsh_c( "pck00008.tpc" ); /* retrieve Mars radii */ bodvrd_c( "MARS", "RADII", 3, &n, radii ); /* package 3D vector */ vpack_c ( 3373.850, -351.034, -117.267, vec ); /* compute planetocentric coordinates */ reclat_c( vec, &pcr, &pclon, &pclat ); /* compute planetodetic coordinates */ recgeo_c( vec, radii[0], f, &pdlon, &pdlat, &pdalt ); /* compute planetographic coordinates */ recpgr_c( "MARS", vec, radii[0], f, &pglon, &pglat, &pgalt ); Reference documents:
Computing azimuth and elevationAPIs:
Brief Example:The following example computes the azimuth/elevation coordinates of the Sun as seen from a location on Mars specified by its planetocentric coordinates: SpiceDouble r; SpiceDouble lon; SpiceDouble lat; SpiceDouble obspos[3]; SpiceDouble et; SpiceDouble azlsta[6]; SpiceDouble ltim; /* load kernels: LSK, PCK, and satellite ephemeris SPK */ furnsh_c( "naif0012.tls" ); furnsh_c( "pck00010.tpc" ); furnsh_c( "mar097s.bsp" ); /* convert planetocentric coordinates of the observer to rectangular coordinates. */ r = 3390.42; lon = 175.30; lat = -14.59; latrec_c( r, lon * rpd_c(), lat * rpd_c(), obspos ); /* convert UTC to ET */ str2et_c ( "2022 JAN 31 01:00", &et ); /* compute azimuth/elevation coordinates with the azimuth increasing clockwise about and the elevation positive towards +Z axis of the local topocentric reference frame. */ azlcpo_c ( "ELLIPSOID", "SUN", et, "CN+S", SPICEFALSE, SPICETRUE, obspos, "MARS", "IAU_MARS", azlsta, <im ); Computing Surface Intercept PointAPIs:
Brief Example:The following example computes the surface intercept point of the MGS MOC NA camera boresight with the surface of Mars modeled as an ellipsoid: SpiceBoolean found; SpiceChar frame[32]; SpiceChar shape[32]; SpiceDouble et; SpiceDouble bsight[3]; SpiceDouble bounds [4][3]; SpiceDouble spoint[3]; SpiceDouble trgepc; SpiceDouble srfvec[3]; SpiceInt n; /* load kernels: LSK, PCK, MGS SCLK, planet/satellite ephemeris SPK, MGS spacecraft SPK, MGS spacecraft CK, MGS FK, and MOC IK */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "mars_iau2000_v0.tpc" ); furnsh_c ( "mgs_sclkscet_00061.tsc" ); furnsh_c ( "mar063.bsp" ); furnsh_c ( "mgs_ext22.bsp" ); furnsh_c ( "mgs_sc_ext22.bc" ); furnsh_c ( "mgs_v10.tf" ); furnsh_c ( "mgs_moc_v20.ti" ); /* retrieve MOC NA camera boresight direction */ getfvn_c ( "MGS_MOC_NA", 4, 32, 32, shape, frame, bsight, &n, bounds ); /* convert UTC to ET */ str2et_c ( "2006 JAN 31 01:00", &et ); /* compute surface intercept point */ sincpt_c ( "Ellipsoid", "MARS", et, "IAU_MARS", "CN+S", "MGS", frame, bsight, spoint, &trgepc, srfvec, &found ); . Computing point on a ray nearest to the body's surfaceAPIs:
Brief Example:The following example computes the tangent point on the MAVEN IUVS instrument boresight nearest to the surface of Mars modeled as an ellipsoid: SpiceChar frame [32]; SpiceChar shape [32]; SpiceDouble bsight [3]; SpiceDouble bounds [12][3]; SpiceDouble tanpt [3]; SpiceDouble alt; SpiceDouble range; SpiceDouble srfpt [3]; SpiceDouble trgepc; SpiceDouble srfvec [3]; SpiceInt n; /* load kernels: LSK, PCK, MAVEN SCLK, planet/satellite ephemeris SPK, MAVEN spacecraft SPK, MAVEN FK, IUVS IK, and MAVEN spacecraft, IPP, and IUVS CKs. */ furnsh_c ( "naif0012.tls" ); furnsh_c ( "pck00010.tpc" ); furnsh_c ( "mvn_sclkscet_00086.tsc" ); furnsh_c ( "mar097s.bsp" ); furnsh_c ( "maven_orb_rec_201001_210101_v1.bsp" ); furnsh_c ( "maven_v09.tf" ); furnsh_c ( "maven_iuvs_v11.ti" ); furnsh_c ( "mvn_sc_rel_201005_201011_v01.bc" ); furnsh_c ( "mvn_app_rel_201005_201011_v01.bc" ); furnsh_c ( "mvn_iuvs_rem_201001_201231_v01.bc" ); /* retrieve IUVS boresight direction */ getfvn_c ( 'MAVEN_IUVS', 12, 32, 32, shape, frame, bsight, &n, bounds ); /* convert UTC to ET */ str2et_c ( "2020-10-11 16:01:43", &et ); /* compute tangent point */ tangpt_c ( "ELLIPSOID", "MARS", et, "IAU_MARS", "CN+S", "TANGENT POINT", "MAVEN", frame, bsight, tanpt, &alt, &range, srfpt, &trgepc, srfvec ); Computing Sub-observer and Sub-solar PointsAPIs:
Brief Example:The following example computes the sub-spacecraft and sub-solar points on Mars, modeled as an ellipsoid, for MGS: SpiceDouble et; SpiceDouble subsc[3]; SpiceDouble subsolar[3]; SpiceDouble srfvec[3]; SpiceDouble trgepc; /* load kernels: LSK, PCK, planet/satellite SPK and MGS spacecraft SPK */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "mars_iau2000_v0.tpc" ); furnsh_c ( "mar063.bsp" ); furnsh_c ( "mgs_ext22.bsp" ); /* convert UTC to ET */ str2et_c ( "2006 JAN 31 01:00", &et ); /* compute sub-spacecraft point */ subpnt_c ( "Near point: ellipsoid", "MARS", et, "IAU_MARS", "LT+S", "MGS", subsc, &trgepc, srfvec ); /* compute sub-solar point */ subslr_c ( "Near point: ellipsoid", "MARS", et, "IAU_MARS", "LT+S", "MGS", subsolar, &trgepc, srfvec ); Computing Illumination AnglesAPIs:
Brief Example:The following example computes the illumination angles for a point specified using planetocentric coordinates, observed by MGS: SpiceDouble r = 3390.42; SpiceDouble lon = 175.30; SpiceDouble lat = -14.59; SpiceDouble point[3]; SpiceDouble et; SpiceDouble srfvec[3]; SpiceDouble trgepc; SpiceDouble phase, solar, emissn; /* load kernels: LSK, PCK, planet/satellite SPK and MGS spacecraft SPK */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "mars_iau2000_v0.tpc" ); furnsh_c ( "mar063.bsp" ); furnsh_c ( "mgs_ext22.bsp" ); /* convert planetocentric r/lon/lat to Cartesian vector */ latrec_c( r, lon * rpd_c(), lat * rpd_c(), point ); /* convert UTC to ET */ str2et_c ( "2006 JAN 31 01:00", &et ); /* compute illumination angles, modeling Mars as an ellipsoid */ ilumin_c ( "Ellipsoid", "MARS", et, "IAU_MARS", "LT+S", "MGS", point, &trgepc, srfvec, &phase, &solar, &emissn ); Computing limb and terminatorAPIs:
Brief Example:The following example computes the apparent limb points on Phobos, modeled by a DSK, as seen from Mars: #define MAXN 10000 SpiceDouble et; SpiceDouble z [3] = { 0.0, 0.0, 1.0 }; SpiceInt npts [MAXN]; SpiceDouble points [MAXN][3]; SpiceDouble trgeps [MAXN]; SpiceDouble tangts [MAXN][3]; /* Load kernels: LSK, PCK, planet/satellite SPK and Phobos DSK */ furnsh_c ( "naif0011.tls" ); furnsh_c ( "pck00010.tpc" ); furnsh_c ( "de430.bsp" ); furnsh_c ( "mar097.bsp" ); furnsh_c ( "phobos512.bds" ); /* Convert UTC to ET */ str2et_c ( "2008 aug 11 00:00:00", &et ); /* Compute limb points in 360 cutting half-planes spaced 1 degree apart about the Mars-Phobos direction. */ limbpt_c ( "TANGENT/DSK/UNPRIORITIZED", "PHOBOS", et, "IAU_PHOBOS", "CN+S", "CENTER", "MARS", z, 1.0/dpr_c(), 360, 1.0e-4, 1.0e-7, MAXN, npts, points, trgeps, tangts ); Computing angular separation between two bodiesAPIs:
Brief Example:The following example computes the apparent angular separation of the Sun and Moon modeled as spheres as observed from the Earth: SpiceDouble et; SpiceDouble angle; /* Load kernels: LSK, PCK, and planetary ephemeris SPK */ furnsh_c ( "naif0012.tls" ); furnsh_c ( "pck00010.tpc" ); furnsh_c ( "de421.bsp" ); /* Convert UTC to ET */ str2et_c ( "2021-12-04T07:33:00", &et ); /* Compute angular separation */ angle = trgsep_c ( et, "SUN", "SPHERE", "IAU_SUN", "MOON", "SPHERE", "IAU_MOON", "EARTH", "CN+S" ); Computing and Propagating Orbital ElementsAPIs:
Brief Example:The following example computes the set of orbital elements for the state of the Mars Express spacecraft at a given time: SpiceInt n; SpiceDouble gm; SpiceDouble et; SpiceDouble state[6]; SpiceDouble lt; SpiceDouble elts[8]; /* load kernels: LSK, MEX trajectory SPK, and gravity PCK */ furnsh_c ( "naif0008.tls" ); furnsh_c ( "ORMM__050901000000_00165.BSP" ); furnsh_c ( "DE403-MASSES.TPC" ); /* retrieve GM for Mars */ bodvrd_c ( "MARS", "GM", 1, &n, gm ); /* convert UTC to ET */ str2et_c ( "2005 SEP 02 04:50:45", &et ); /* compute state of MEX at given UTC */ spkezr_c ( "MEX", et, "MARSIAU", "NONE", "MARS", state, < ); /* compute orbital elements */ oscelt_c ( state, et, gm, elts ); Checking for in Field-Of-View (FOV) conditionsAPIs:
Brief Example:The following example determines if Phoebe is in the CASSINI ISS NAC FOV on 2004-06-11 18:00 UTC: SpiceDouble et; SpiceBoolean visibl; /* Load kernels. */ furnsh_c( "cas_2004_v17.tm" ); /* Convert UTC to ET. */ str2et_c( "2004-06-11 18:00", &et ); /* Check for in-FOV condition. */ fovtrg_c ( "CASSINI_ISS_NAC", "PHOEBE", "ELLIPSOID", "IAU_PHOEBE", "CN+S", "CASSINI", et, &visibl ); Checking for occultation conditionsAPIs:
Brief Example:The following example determines if the Sun is occulted by Saturn as seen from CASSINI on 2005-05-03 06:00 UTC, with both Sun and Saturn modeled as ellipsoids: SpiceDouble et; SpiceInt ocltid; /* Load kernels. */ furnsh_c( "cas_2005_v17.tm" ); /* Convert UTC to ET. */ str2et_c ( "2005-05-03 06:00", &et ); /* Check for in-FOV condition. */ occult_c ( "SATURN", "ELLIPSOID", "IAU_SATURN", "SUN", "ELLIPSOID", "IAU_SUN", "CN", "CASSINI", et, &ocltid ); if ( ocltid > 0 ) { printf ( "CASSINI IS IN SATURN SHADOW.\n" ); } Finding times of events satisfying numerical constraintsAPIs:
Brief Example:The following example determines time intervals between Jan 1 and and April 1, 2007 when the distance between the Moon and the Earth was greater than 400,000 km. #define MAXWIN 200 SPICEDOUBLE_CELL ( cnfine, MAXWIN ); SPICEDOUBLE_CELL ( result, MAXWIN ); SpiceDouble adjust; SpiceDouble et0; SpiceDouble et1; SpiceDouble refval; SpiceDouble step; /* Load kernels. */ furnsh_c( "naif0008.tls" ); furnsh_c( "de421.bsp" ); /* Store the time bounds in the confinement window. */ str2et_c ( "2007 JAN 1", &et0 ); str2et_c ( "2007 APR 1", &et1 ); wninsd_c ( et0, et1, &cnfine ); /* Set search parameters. Use a step size of 1 day (in units of seconds). */ step = spd_c(); refval = 4.e5; adjust = 0.0; /* Perform search. */ gfdist_c ( "MOON", "NONE", "EARTH", ">", refval, adjust, step, MAXWIN, &cnfine, &result ); Reference documents:
Finding times of events satisfying FOV constraintsAPIs:
Brief Example:The following example determines time intervals between 09:00 and 11:15 UTC on Jun 11, 2004 when Saturn's satellite Phoebe was within the FOV of the Cassini narrow angle camera (CASSINI_ISS_NAC). #define MAXWIN 10000 SPICEDOUBLE_CELL ( cnfine, MAXWIN ); SPICEDOUBLE_CELL ( result, MAXWIN ); SpiceDouble et0; SpiceDouble et1; SpiceDouble stepsz; /* Load kernels. */ furnsh_c( "naif0009.tls" ); furnsh_c( "cpck05Mar2004.tpc" ); furnsh_c( "981005_PLTEPH-DE405S.bsp" ); furnsh_c( "020514_SE_SAT105.bsp" ); furnsh_c( "030201AP_SK_SM546_T45.bsp" ); furnsh_c( "cas_v37.tf" ); furnsh_c( "04135_04171pc_psiv2.bc" ); furnsh_c( "cas00084.tsc" ); furnsh_c( "cas_iss_v09.ti" ); /* Store the time bounds in the confinement window. */ str2et_c ( "2004 JUN 11 09:00", &et0 ); str2et_c ( "2004 JUN 11 11:15", &et1 ); wninsd_c ( et0, et1, &cnfine ); /* Set search parameters. Use a step size of 10 seconds. */ stepsz = 10.0; /* Perform search. */ gftfov_c ( "CASSINI_ISS_NAC", "PHOEBE", "ELLIPSOID", "IAU_PHOEBE", "LT+S", "CASSINI", stepsz, &cnfine, &result ); Reference documents:
Finding times of occultationsAPIs:
Brief Example:The following example determines time intervals in December, 2001 when the Sun is occulted by the Moon (solar eclipses) as seen from the center of the Earth, with both Sun and Moon modeled as ellipsoids: #define MAXWIN 200 SPICEDOUBLE_CELL ( cnfine, MAXWIN ); SPICEDOUBLE_CELL ( result, MAXWIN ); SpiceDouble et0; SpiceDouble et1; SpiceDouble step; /* Load kernels. */ furnsh_c( "naif0008.tls" ); furnsh_c( "de421.bsp" ); furnsh_c( "pck00008.tpc" ); /* Store the time bounds in the confinement window. */ str2et_c ( "2001 DEC 01", &et0 ); str2et_c ( "2002 JAN 01", &et1 ); wninsd_c ( et0, et1, &cnfine ); /* Set search parameters. Select a 3-minute step. */ step = 180.0; /* Perform search. */ gfoclt_c ( "ANY", "MOON", "ELLIPSOID", "IAU_MOON", "SUN", "ELLIPSOID", "IAU_SUN", "LT", "EARTH", step, &cnfine, &result ); Reference documents:
Converting from and to rectangular coordinatesAPIs:
Brief Example:The following example computes the planetocentric, planetodetic and planetographic coordinates for a point given as a Cartesian vector with respect to Mars in the Mars body-fixed frame (IAU_MARS): SpiceDouble vec[3]; SpiceDouble radii[3]; SpiceDouble f; SpiceDouble pcr, pclon, pclat; SpiceDouble pdalt, pdlon, pdlat; SpiceDouble pgalt, pglon, pglat; SpiceInt n; /* load PCK file */ furnsh_c( "pck00008.tpc" ); /* retrieve Mars radii */ bodvrd_c( "MARS", "RADII", 3, &n, radii ); /* pack 3D vector */ vpack_c ( 3373.850, -351.034, -117.267, vec ); /* compute planetocentric coordinates */ reclat_c( vec, &pcr, &pclon, &pclat ); /* compute planetodetic coordinates */ recgeo_c( vec, radii[0], f, &pdlon, &pdlat, &pdalt ); /* compute planetographic coordinates */ recpgr_c( "MARS", vec, radii[0], f, &pglon, &pglat, &pgalt ); Converting from and to Spherical CoordinatesAPIs:
Brief Example:The following example computes the spherical coordinates of a point specified as a Cartesian vector: SpiceDouble vec[3]; SpiceDouble r; SpiceDouble colat; SpiceDouble lon; vpack_c ( 1.0, 1.0, 1.0, vec ); recsph_c ( vec, &r, &colat, &lon ); Converting from and to cylindrical coordinatesAPIs:
Brief Example:The following example computes the cylindrical coordinates of a point specified as a Cartesian vector: SpiceDouble vec[3]; SpiceDouble r; SpiceDouble lon; SpiceDouble z; vpack_c ( 1.0, 1.0, 1.0, vec ); reccyl_c ( vec, &r, &lon, &z ); Converting from and to Latitudinal CoordinatesAPIs:
Brief Example:The following example converts the planetocentric coordinates of a point to a Cartesian vector: SpiceDouble vec[3]; SpiceDouble r = 3390.42; SpiceDouble lon = 175.30; SpiceDouble lat = -14.59; latrec_c( r, lon * rpd_c(), lat * rpd_c(), vec ); Converting from and to R, RA, and DECAPIs:
Brief Example:The following example computes the unit vector corresponding to an RA and DEC given in degrees: SpiceDouble ra = 120.0; SpiceDouble dec = -30.0; SpiceDouble vec[3]; radrec_c( 1.0, ra * rpd_c(), dec * rpd_c(), vec ); Converting from and to Geodetic CoordinatesAPIs:
Brief Example:The following example converts the areodetic coordinates of a landing site (Lon = 175.3 deg, Lat = -14.59 deg, Alt = -1.91 km), given relative to the IAU 2000 Mars ellipsoid, to a Cartesian vector: SpiceDouble lon; SpiceDouble lat; SpiceDouble alt; SpiceDouble radii[3]; SpiceDouble f; SpiceDouble vec[3]; SpiceInt n; furnsh_c( "pck00008.tpc" ); bodvrd_c( "MARS", "RADII", 3, &n, radii ); lon = 175.30 * rpd_c(); lat = -14.59 * rpd_c(); alt = -1.91; f = (radii[0]-radii[2])/radii[0]; georec_c( lon, lat, alt, radii[0], f, vec ); Transforming states from one coordinate system to anotherAPIs:
Brief Example:The following example converts a state specified in the rectangular coordinate system (X, Y, Z, DX, DY, DZ) to the state specified in the latitudinal coordinate system (R, LONG, LAT, DR, DLONG, DLAT): SpiceDouble istate[6]; SpiceDouble ostate[6]; istate[0] = 1000.0; istate[1] = 2000.0; istate[2] = 3000.0; istate[3] = 20.0; istate[4] = -40.0; istate[6] = -60.0; xfmsta_c ( istate, "RECTANGULAR", "LATITUDINAL", " ", ostate ); printf( "R = %20.10f KM\n", ostate[0] ); printf( "LONG = %20.10f RAD\n", ostate[1] ); printf( "LAT = %20.10f RAD\n", ostate[2] ); printf( "DR = %20.10f KM/S\n", ostate[3] ); printf( "DLONG = %20.10f RAD/S\n", ostate[4] ); printf( "DLAT = %20.10f RAD/S\n", ostate[5] ); Performing simple operations on 3D vectorsAPIs:
Brief Example:The following example prints the angular separation between two 3D vectors in degrees: SpiceDouble a[3]; SpiceDouble b[3]; vpack_c( 1.0, 0.0, 0.0, a ); vpack_c( 1.0, 1.0, 0.0, b ); printf( "angular separation, deg = %12.3f\n", vsep_c(a,b) * dpr_c() ); Projecting, Combining and Rotating 3D vectorsAPIs:
Brief Example:The following example finds the projection of one 3D vector onto another 3D vector: SpiceDouble a[3]; SpiceDouble b[3]; SpiceDouble c[3]; vproj_c( a, b, c ); Performing Simple Operations on 3x3 MatricesAPIs:
Brief Example:The following example multiples two matrices and converts the resulting matrix to a SPICE-style quaternion: SpiceDouble mat1[3][3]; SpiceDouble mat2[3][3]; SpiceDouble mat3[3][3]; SpiceDouble q[4]; mxm_c( mat1, mat2, mat3 ); m2q_c( mat3, q ); Creating and Converting Transformation MatricesAPIs:
Brief Example:The following example creates a transformation matrix from right ascension, declination, and twist given in degrees: SpiceDouble ra = 10.0; SpiceDouble dec = 20.0; SpiceDouble twist = -135.0; SpiceDouble mat[3][3]; ra = ra * rpd_c(); dec = dec * rpd_c(); twist = twist * rpd_c(); eul2m_c( twist, halfpi_c() - dec, ra, 3, 2, 3, mat ); Reference documents:
Accessing Physical and Mathematical ConstantsAPIs:
Brief Example:The following example sets angle to pi/2 and prints it in degrees: SpiceDouble angle; angle = halfpi_c(); printf( "angle, deg = %12.3f\n", angle * dpr_c() ); |