kbe3d-satellite 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/README.md +1 -1
- package/dist/dts/index.d.ts +67 -9
- package/dist/kbe3d-satellite.js +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
package/dist/README.md
CHANGED
package/dist/dts/index.d.ts
CHANGED
|
@@ -393,6 +393,72 @@ export declare interface OrbitPropagatorResult {
|
|
|
393
393
|
*/
|
|
394
394
|
alt: number;
|
|
395
395
|
};
|
|
396
|
+
/**
|
|
397
|
+
* 平均轨道根数 - ^[当方法传入`isGetDetails`参数为`true`并且`isUseGPU`参数为`false`时返回]
|
|
398
|
+
* @remarks
|
|
399
|
+
* 卫星在传播时刻的瞬时平均轨道根数(Singly Averaged Mean Elements)
|
|
400
|
+
*/
|
|
401
|
+
meanElements?: {
|
|
402
|
+
/**
|
|
403
|
+
* 半长轴
|
|
404
|
+
*
|
|
405
|
+
* @remarks
|
|
406
|
+
* 轨道椭圆长轴的一半,决定轨道大小和周期
|
|
407
|
+
*
|
|
408
|
+
* @unit 地球半径 (ER)
|
|
409
|
+
* @example 1.3518 ER ≈ 8619 km (6378 × am)
|
|
410
|
+
*/
|
|
411
|
+
am: number;
|
|
412
|
+
/**
|
|
413
|
+
* 离心率
|
|
414
|
+
*
|
|
415
|
+
* @remarks
|
|
416
|
+
* 轨道形状,0表示正圆,0-1之间为椭圆
|
|
417
|
+
*
|
|
418
|
+
* @range 0 ≤ e < 1
|
|
419
|
+
*/
|
|
420
|
+
em: number;
|
|
421
|
+
/**
|
|
422
|
+
* 轨道倾角
|
|
423
|
+
*
|
|
424
|
+
* @remarks
|
|
425
|
+
* 轨道平面与地球赤道平面的夹角
|
|
426
|
+
*
|
|
427
|
+
* @unit 弧度 (rad)
|
|
428
|
+
* @range 0 ~ π
|
|
429
|
+
*/
|
|
430
|
+
im: number;
|
|
431
|
+
/**
|
|
432
|
+
* 升交点赤经
|
|
433
|
+
*
|
|
434
|
+
* @remarks
|
|
435
|
+
* 从春分点向东量到升交点的角度,决定轨道面在空间中的指向
|
|
436
|
+
*
|
|
437
|
+
* @unit 弧度 (rad)
|
|
438
|
+
* @range 0 ~ 2π
|
|
439
|
+
*/
|
|
440
|
+
Om: number;
|
|
441
|
+
/**
|
|
442
|
+
* 近地点幅角
|
|
443
|
+
*
|
|
444
|
+
* @remarks
|
|
445
|
+
* 从升交点沿运动方向量到近地点的角度,决定椭圆在轨道面内的指向
|
|
446
|
+
*
|
|
447
|
+
* @unit 弧度 (rad)
|
|
448
|
+
* @range 0 ~ 2π
|
|
449
|
+
*/
|
|
450
|
+
om: number;
|
|
451
|
+
/**
|
|
452
|
+
* 平近点角
|
|
453
|
+
*
|
|
454
|
+
* @remarks
|
|
455
|
+
* 假想的匀速运动角度,用于描述卫星在轨道上的位置
|
|
456
|
+
*
|
|
457
|
+
* @unit 弧度 (rad)
|
|
458
|
+
* @range -π ~ π
|
|
459
|
+
*/
|
|
460
|
+
mm: number;
|
|
461
|
+
};
|
|
396
462
|
}
|
|
397
463
|
|
|
398
464
|
/**
|
|
@@ -500,15 +566,7 @@ export { _satellitejs }
|
|
|
500
566
|
* - isGetDetails: 是否获取更多详细信息,默认为false
|
|
501
567
|
* - isUseGPU: 是否使用GPU计算,默认为false
|
|
502
568
|
*
|
|
503
|
-
* @returns
|
|
504
|
-
* - satrec: 解析后的卫星记录对象,包含轨道参数
|
|
505
|
-
* - result: 包含时间、ECF坐标、ECI坐标、速度和地理坐标的数组
|
|
506
|
-
* 每个结果项包含:
|
|
507
|
-
* - time: 对应时刻的ISO格式时间戳
|
|
508
|
-
* - positionEcf: 地固坐标系中的位置向量
|
|
509
|
-
* - positionEci: 惯性坐标系中的位置向量
|
|
510
|
-
* - velocityEci: 惯性坐标系中的速度向量
|
|
511
|
-
* - position: 地理坐标(纬度、经度、高度)
|
|
569
|
+
* @returns 返回包含卫星记录和位置结果数组的对象
|
|
512
570
|
*/
|
|
513
571
|
export declare function sgp4Orbit(params: OrbitPropagatorParams, config?: OrbitPropagatorConfig): Promise<OrbitPropagatorResult[] | undefined>;
|
|
514
572
|
|
package/dist/kbe3d-satellite.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"satellite.js";import*as t from"tle.js";import n,{GpuPropagator as i,WasmElements as r,WasmConstants as o,WasmGpuConsts as s}from"sgp4.gl";import a from"sgp4.gl/wasm?url";function c(e){return e&&Array.isArray(e)}function l(e,t,n){const i=["[KBSatellite warn]: “"+(c(t)?t[0]:t)+"”.",...c(t)?t.slice(1):[],n?.message];if(console.warn(...i),"THROW"===e&&n)throw n}function E(e){const t=["[KBSatellite Info]: “"+(c(e)?e[0]:e)+"”.",...c(e)?e.slice(1):[]];console.log(...t)}const T=0,_=48021e-8,g=5995e-8,O=0,u="U",N=99999,A=9999,p=99999,f="99999",m="99999";function I(e){const t=Math.sqrt(3986004418e5/e**3),n=86400/(2*Math.PI)*t;return{radPerSec:t,revPerDay:n,revPerDayFormatted:Math.round(100*n)/100}}function h(e){const t=2*e*Math.PI/86400;return Number(((3986004418e5/t**2)**(1/3)).toFixed(4))}function d(e){const t=e/1e3;return Math.sqrt(t**3*4*Math.PI**2/398600.4418)}function C(e){const t=["EPOCH","MEAN_MOTION","ECCENTRICITY","INCLINATION","RA_OF_ASC_NODE","ARG_OF_PERICENTER","MEAN_ANOMALY"].filter(t=>void 0===e[t]);t.length>0&&l("THROW","缺少必要字段: "+t.join(", "),new Error("缺少必要字段: "+t.join(", ")));return{EPOCH:e.EPOCH,MEAN_MOTION:e.MEAN_MOTION,ECCENTRICITY:e.ECCENTRICITY,INCLINATION:e.INCLINATION,RA_OF_ASC_NODE:e.RA_OF_ASC_NODE,ARG_OF_PERICENTER:e.ARG_OF_PERICENTER,MEAN_ANOMALY:e.MEAN_ANOMALY,EPHEMERIS_TYPE:e.EPHEMERIS_TYPE??T,BSTAR:e.BSTAR??_,MEAN_MOTION_DOT:e.MEAN_MOTION_DOT??g,MEAN_MOTION_DDOT:e.MEAN_MOTION_DDOT??O,CLASSIFICATION_TYPE:e.CLASSIFICATION_TYPE??u,NORAD_CAT_ID:e.NORAD_CAT_ID??N,ELEMENT_SET_NO:e.ELEMENT_SET_NO??A,REV_AT_EPOCH:e.REV_AT_EPOCH??p,OBJECT_NAME:e.OBJECT_NAME??f,OBJECT_ID:e.OBJECT_ID??m}}function M(e,t){return(e-t)/60/1e3}function w(e,n={}){const[i,r]=e;if(69!=i.length||69!=r.length)throw new Error("TLE 格式不正确,长度必须等于69");let o;try{o=t.parseTLE([i,r])}catch(I){l("THROW",["TLE 解析失败:\n",i+"\n",r+"\n"],I)}const s=t.getCatalogNumber(o,!0),a=t.getClassification(o,!0)||"U",c=t.getEpochTimestamp(o),E=new Date(c).toISOString(),T=t.getFirstTimeDerivative(o,!0),_=t.getSecondTimeDerivative(o,!0),g=10*t.getBstarDrag(o,!0),O=Number.parseInt(i.substring(62,63).trim()||"0"),u=t.getTleSetNumber(o,!0),N=t.getInclination(o,!0),A=t.getRightAscension(o,!0),p=t.getEccentricity(o,!0),f=t.getPerigee(o,!0),m=t.getMeanAnomaly(o,!0);return{EPOCH:E,MEAN_MOTION:t.getMeanMotion(o,!0),ECCENTRICITY:p,INCLINATION:N,RA_OF_ASC_NODE:A,ARG_OF_PERICENTER:f,MEAN_ANOMALY:m,NORAD_CAT_ID:s,EPHEMERIS_TYPE:O,BSTAR:g,MEAN_MOTION_DOT:T,MEAN_MOTION_DDOT:_,CLASSIFICATION_TYPE:a,ELEMENT_SET_NO:u,REV_AT_EPOCH:t.getRevNumberAtEpoch(o,!0),OBJECT_NAME:n?.OBJECT_NAME??"99999",OBJECT_ID:n?.OBJECT_ID??"99999",...n}}function S(e){const t=C(e),n=new Date(t.EPOCH),i=n.getUTCFullYear().toString().slice(-2).padStart(2,"0"),r=new Date(Date.UTC(n.getUTCFullYear(),0,1)),o=((n.getTime()-r.getTime())/864e5+1).toFixed(8).padStart(12,"0");let s="1 "+t.NORAD_CAT_ID.toString().padStart(5," ");s+=t.CLASSIFICATION_TYPE,s+=" "+(t.OBJECT_ID?.padEnd(8," ")||"00000AAA "),s+=" "+i+o;const a=t.MEAN_MOTION_DOT;s+=" "+Number(a).toFixed(8).padStart(9,"0");const c=t.MEAN_MOTION_DDOT;s+=" "+y(Number(c),5);s+=" "+y(Number(t.BSTAR),5),s+=" "+t.EPHEMERIS_TYPE,s+=" "+t.ELEMENT_SET_NO.toString().padStart(4," ");const l=P(s);s+=l;let E="2 "+t.NORAD_CAT_ID.toString().padStart(5," ");E+=" "+Number(t.INCLINATION).toFixed(4).padStart(8," "),E+=" "+Number(t.RA_OF_ASC_NODE).toFixed(4).padStart(8," ");E+=" "+Math.abs(Number(t.ECCENTRICITY)).toFixed(7).slice(2).padStart(7,"0"),E+=" "+Number(t.ARG_OF_PERICENTER).toFixed(4).padStart(8," "),E+=" "+Number(t.MEAN_ANOMALY).toFixed(4).padStart(8," ");E+=" "+Number(t.MEAN_MOTION).toFixed(8).padStart(11,"0");E+=Number(t.REV_AT_EPOCH).toString().padStart(5," ");const T=P(E);return E+=T,{line1:s,line2:E,checksum1:l,checksum2:T,omm:t}}function D(e){const t=I(e.semimajorAxis);let n=e.epoch.replaceAll(" ","T");n=n.endsWith("Z")?n:n+"Z";return S({EPOCH:n,MEAN_MOTION:t.revPerDay,ECCENTRICITY:e.eccentricity,INCLINATION:e.inclination,RA_OF_ASC_NODE:e.raan,ARG_OF_PERICENTER:e.argPerigee,MEAN_ANOMALY:e.meanAnomaly,...e.OMMInputForce})}function y(e,t){if(0===e)return" 00000-0";const n=e.toExponential(t).match(/^(-?)(\d+\.\d+)e([+-]\d+)$/i);if(!n)return" 00000-0";const[,i,r,o]=n,s=r.replace(".","").substring(0,t),a=Number.parseInt(o);return("-"===i?"-":" ")+s+(a>=0?"+":"-")+Math.abs(a).toString().padStart(1,"0")}function P(e){let t=0;for(let n=0;n<e.length;n++){const i=e[n];"-"===i?t+=1:!Number.isNaN(Number.parseInt(i))&&(t+=Number.parseInt(i))}return t%10}async function R(t,c={isGetDetails:!1,isUseGPU:!1}){try{const T=Date.now();let _;return _=c?.isUseGPU?await async function(t,c={isGetDetails:!1,isUseGPU:!0}){const T=Date.now();await n({module_or_path:a}),E(["wasm首次加载:",(Date.now()-T)/1e3,"秒"]);const _=Array.isArray(t.kepler);let g,O;if(_){O=t.kepler;g=C(w(O))}else{const e=D(t.kepler);O=[e.line1,e.line2],g=e.omm}const u=g.EPOCH.replaceAll(" ","T"),N=t.startTime.replaceAll(" ","T"),A=t.stopTime.replaceAll(" ","T"),p=new Date(u.endsWith("Z")?u:u+"Z").getTime(),f=new Date(N.endsWith("Z")?N:N+"Z").getTime()-p,m=new Date(A.endsWith("Z")?A:A+"Z").getTime()-p,I=t.step,h=f/1e3,d=m/1e3,M=Math.floor((d-h)/I)+1,S=new Float64Array(M);for(let e=0;e<M;e++){const t=h+e*I;S[e]=t/60}let y;try{y=await i.new_for_web()}catch{try{y=await i.new_for_web_gl()}catch(b){l("THROW","❌ WebGPU 不可用",b)}}const P=g.OBJECT_NAME||"Unknown";let R;try{R=r.from_tle((new TextEncoder).encode(P),(new TextEncoder).encode(O[0]),(new TextEncoder).encode(O[1]))}catch(H){l("THROW",["TLE 解析失败:\n",O[0]+"\n",O[1]+"\n"],H)}const L=o.from_elements(R),G=new Float32Array(6*M),F=5e4;for(let e=0;e<M;e+=F){const t=Math.min(e+F,M),n=t-e,i=Array.from({length:n}).map(()=>s.from_constants(L)),r=S.slice(e,t),o=await y.propagate_batch_f32(i,r);G.set(o,6*e)}const U=Array.from({length:M});for(let n=0;n<M;n++){const t=6*n,i={x:G[t],y:G[t+1],z:G[t+2]},r=new Date(p+1e3*(h+n*I));if(c.isGetDetails){const o=e.gstime(r),s={x:G[t+3],y:G[t+4],z:G[t+5]},a=e.eciToEcf(i,o),c=e.eciToEcf(s,o),l=e.eciToGeodetic(i,o),E={lat:e.degreesLat(l.latitude),lng:e.degreesLong(l.longitude),alt:1e3*l.height};U[n]={time:r.toISOString(),positionEci:i,positionEcf:a,velocityEci:s,velocityEcf:c,position:E}}else U[n]={time:r.toISOString(),positionEci:i}}return U}(t,c):await async function(t,n={isGetDetails:!1,isUseGPU:!1}){const i=Array.isArray(t.kepler);let r,o;if(i){r=e.twoline2satrec(t.kepler[0],t.kepler[1]);o=C(w(t.kepler)),h(o.MEAN_MOTION)}else{o=D(t.kepler).omm,r=e.json2satrec(o)}const s=o.EPOCH.replaceAll(" ","T"),a=t.startTime.replaceAll(" ","T"),c=t.stopTime.replaceAll(" ","T"),l=new Date(s.endsWith("Z")?s:s+"Z").getTime(),E=new Date(a.endsWith("Z")?a:a+"Z").getTime()-l,T=new Date(c.endsWith("Z")?c:c+"Z").getTime()-l,_=t.step,g=[],O=T/1e3;let u,N;for(let A=E/1e3;A<=O;A+=_){const t=e.sgp4(r,Number((A/60).toFixed(3)));if(t){u=new Date(l+1e3*A),N=e.gstime(u);const i=t.position;if(n.isGetDetails){const n=e.eciToEcf(i,N),r=e.eciToGeodetic(i,N),o=t.velocity,s=e.eciToEcf(o,N),a={lat:e.degreesLat(r.latitude),lng:e.degreesLong(r.longitude),alt:1e3*r.height};g.push({time:u.toISOString(),positionEci:i,positionEcf:n,velocityEci:o,velocityEcf:s,position:a})}else g.push({time:u.toISOString(),positionEci:i})}}return g}(t,c),E(["sgp4耗时:",(Date.now()-T)/1e3,"秒"]),_}catch(T){l("THROW","sgp4Orbit函数运行异常",T)}}async function L(c,T={isGetDetails:!1,isUseGPU:!0}){try{const _=Date.now();let g;return g=T?.isUseGPU?await async function(c,T={isGetDetails:!1,isUseGPU:!0}){let _=!1,g=null,O=null,u=!1;const N=/* @__PURE__ */new Map,A=[],p=[];let f=/* @__PURE__ */new Map,m=[],I=[],h=[];async function d(){if(_)return!0;try{await n({module_or_path:a});try{g=await i.new_for_web()}catch{g=await i.new_for_web_gl()}if(!g)return l("THROW","❌ GPU 传播器创建失败"),!1;const T=[];h=[];for(let n=0;n<c.length;n++){const i=c[n],{kepler:s,id:a}=i;let E,_;if(Array.isArray(s))[E,_]=s;else{const e=D(s);E=e.line1,_=e.line2}try{const e=t.parseTLE([E,_]),s=t.getEpochTimestamp(e);h.push(s);const l=r.from_tle((new TextEncoder).encode(String(i.id)),(new TextEncoder).encode(E),(new TextEncoder).encode(_)),g=o.from_elements(l);T.push(g),N.set(a,{epochTimestamp:s}),A.push(a),p.push(c[n])}catch(e){l("NOT_THROW",["TLE 解析失败:\n",E+"\n",_+"\n"],e);continue}}return I=T.map(e=>s.from_constants(e)),O=g.register_const_set(I),f=/* @__PURE__ */new Map,m=Array.from({length:p.length}),_=!0,E(["GPU 批处理初始化完成,卫星数量: "+p.length]),!0}catch(T){return l("THROW","GPU 初始化失败",T),!1}}async function C(t){if(_&&g&&null!==O&&!u){u=!0;try{const n=new Float64Array(p.length);for(let e=0;e<p.length;e++){const i=N.get(A[e]);if(i){const r=M(t,i.epochTimestamp);n[e]=r}else n[e]=0}const i=await g.propagate_registered_f32(O,n),r=Array.from({length:p.length});for(let s=0;s<p.length;s++){const n=6*s,o={x:i[n],y:i[n+1],z:i[n+2]},a=new Date(t);if(T.isGetDetails){const t=e.gstime(a),c={x:i[n+3],y:i[n+4],z:i[n+5]},l=e.eciToEcf(o,t),E=e.eciToEcf(c,t),T=e.eciToGeodetic(o,t);r[s]={time:a.toISOString(),positionEci:o,positionEcf:l,velocityEci:c,velocityEcf:E,position:{lat:e.degreesLat(T.latitude),lng:e.degreesLong(T.longitude),alt:1e3*T.height}}}else r[s]={time:a.toISOString(),positionEci:o}}m=r;const o=/* @__PURE__ */new Map;for(let e=0;e<p.length;e++)o.set(A[e],m[e]);return f=o,f}catch(n){return void console.error("GPU 更新错误:",n)}finally{u=!1}}}function w(){return f}function S(e){return f.get(e)}function y(){return _}function P(){return u}async function R(){if(_){if(_=!1,g&&null!==O){try{g.unregister_const_set(O)}catch(e){l("NOT_THROW","释放 GPU 常量集失败",e)}g=null,O=null}f.clear(),m=[],N.clear(),E(["GPU 批处理内存占用已清理"])}}return await d(),{dispose:R,isProcessing:P,isInitialized:y,getCurrentPositions:w,getPosition:S,update:C}}(c,T):await async function(n,i={isGetDetails:!1,isUseGPU:!1}){let r=!1,o=!1;const s=/* @__PURE__ */new Map,a=[],c=[];let T=/* @__PURE__ */new Map,_=[];async function g(){if(r)return!0;try{for(let i=0;i<n.length;i++){const r=n[i],{kepler:o,id:E}=r;let T,_;if(Array.isArray(o)){const[n,i]=o;T=e.twoline2satrec(n,i);const r=t.parseTLE([n,i]);_=t.getEpochTimestamp(r)}else{const t=D(o).omm;T=e.json2satrec(t);const n=t.EPOCH.replaceAll(" ","T");_=new Date(n.endsWith("Z")?n:n+"Z").getTime()}T&&!T.error?(s.set(E,{epochTimestamp:_,satrec:T}),a.push(E),c.push(r)):l("NOT_THROW","卫星 "+E+" TLE 解析失败: "+T?.error,new Error("SatRec error: "+T?.error))}return 0===c.length?(l("THROW","没有可用的卫星数据"),!1):(T=/* @__PURE__ */new Map,_=Array.from({length:c.length}),r=!0,E(["CPU 批处理初始化完成,卫星数量: "+c.length]),!0)}catch(i){return l("THROW","CPU 批处理初始化失败",i),!1}}async function O(t){if(r&&!o){o=!0;try{const n=Array.from({length:c.length});for(let o=0;o<c.length;o++){const r=a[o],c=s.get(r);if(!c)continue;const l=(t-c.epochTimestamp)/6e4,E=e.sgp4(c.satrec,l);if(!E)continue;const T=E.position,_=new Date(t);if(i.isGetDetails){const t=e.gstime(_),i=E.velocity,r=e.eciToEcf(T,t),s=e.eciToEcf(i,t),a=e.eciToGeodetic(T,t);n[o]={time:_.toISOString(),positionEci:T,positionEcf:r,velocityEci:i,velocityEcf:s,position:{lat:e.degreesLat(a.latitude),lng:e.degreesLong(a.longitude),alt:1e3*a.height}}}else n[o]={time:_.toISOString(),positionEci:T}}_=n;const r=/* @__PURE__ */new Map;for(let e=0;e<c.length;e++)_[e]&&r.set(a[e],_[e]);return T=r,T}catch(n){return void console.error("CPU 更新错误:",n)}finally{o=!1}}}function u(){return T}function N(e){return T.get(e)}function A(){return r}function p(){return o}async function f(){r&&(r=!1,T.clear(),_=[],s.clear(),E(["CPU 批处理内存占用已清理"]))}return await g(),{dispose:f,isProcessing:p,isInitialized:A,getCurrentPositions:u,getPosition:N,update:O}}(c,T),E(["sgp4耗时:",(Date.now()-_)/1e3,"秒"]),g}catch(_){l("THROW","sgp4OrbitLive函数运行异常",_)}}export{e as _satellitejs,t as _tlejs,C as getFullOmm,I as getMeanMotion,M as getMinutesSinceEpoch,d as getPeriod,h as getSemiMajorAxis,R as sgp4Orbit,L as sgp4OrbitLive,D as transKeplerToTle,S as transOmmToTle,w as transTleToOmm};
|
|
1
|
+
import*as e from"satellite.js";import*as t from"tle.js";import n,{GpuPropagator as r,WasmElements as i,WasmConstants as o,WasmGpuConsts as s}from"sgp4.gl";import a from"sgp4.gl/wasm?url";function c(e){return e&&Array.isArray(e)}function l(e,t,n){const r=["[KBSatellite warn]: “"+(c(t)?t[0]:t)+"”.",...c(t)?t.slice(1):[],n?.message];if(console.warn(...r),"THROW"===e&&n)throw n}function E(e){const t=["[KBSatellite Info]: “"+(c(e)?e[0]:e)+"”.",...c(e)?e.slice(1):[]];console.log(...t)}const T=0,_=48021e-8,g=5995e-8,O=0,u="U",N=99999,p=9999,m=99999,A="99999",f="99999";function I(e){const t=Math.sqrt(3986004418e5/e**3),n=86400/(2*Math.PI)*t;return{radPerSec:t,revPerDay:n,revPerDayFormatted:Math.round(100*n)/100}}function d(e){const t=2*e*Math.PI/86400;return Number(((3986004418e5/t**2)**(1/3)).toFixed(4))}function h(e){const t=e/1e3;return Math.sqrt(t**3*4*Math.PI**2/398600.4418)}function C(e){const t=["EPOCH","MEAN_MOTION","ECCENTRICITY","INCLINATION","RA_OF_ASC_NODE","ARG_OF_PERICENTER","MEAN_ANOMALY"].filter(t=>void 0===e[t]);t.length>0&&l("THROW","缺少必要字段: "+t.join(", "),new Error("缺少必要字段: "+t.join(", ")));return{EPOCH:e.EPOCH,MEAN_MOTION:e.MEAN_MOTION,ECCENTRICITY:e.ECCENTRICITY,INCLINATION:e.INCLINATION,RA_OF_ASC_NODE:e.RA_OF_ASC_NODE,ARG_OF_PERICENTER:e.ARG_OF_PERICENTER,MEAN_ANOMALY:e.MEAN_ANOMALY,EPHEMERIS_TYPE:e.EPHEMERIS_TYPE??T,BSTAR:e.BSTAR??_,MEAN_MOTION_DOT:e.MEAN_MOTION_DOT??g,MEAN_MOTION_DDOT:e.MEAN_MOTION_DDOT??O,CLASSIFICATION_TYPE:e.CLASSIFICATION_TYPE??u,NORAD_CAT_ID:e.NORAD_CAT_ID??N,ELEMENT_SET_NO:e.ELEMENT_SET_NO??p,REV_AT_EPOCH:e.REV_AT_EPOCH??m,OBJECT_NAME:e.OBJECT_NAME??A,OBJECT_ID:e.OBJECT_ID??f}}function M(e,t){return(e-t)/60/1e3}function w(e,n={}){const[r,i]=e;if(69!=r.length||69!=i.length)throw new Error("TLE 格式不正确,长度必须等于69");let o;try{o=t.parseTLE([r,i])}catch(I){l("THROW",["TLE 解析失败:\n",r+"\n",i+"\n"],I)}const s=t.getCatalogNumber(o,!0),a=t.getClassification(o,!0)||"U",c=t.getEpochTimestamp(o),E=new Date(c).toISOString(),T=t.getFirstTimeDerivative(o,!0),_=t.getSecondTimeDerivative(o,!0),g=10*t.getBstarDrag(o,!0),O=Number.parseInt(r.substring(62,63).trim()||"0"),u=t.getTleSetNumber(o,!0),N=t.getInclination(o,!0),p=t.getRightAscension(o,!0),m=t.getEccentricity(o,!0),A=t.getPerigee(o,!0),f=t.getMeanAnomaly(o,!0);return{EPOCH:E,MEAN_MOTION:t.getMeanMotion(o,!0),ECCENTRICITY:m,INCLINATION:N,RA_OF_ASC_NODE:p,ARG_OF_PERICENTER:A,MEAN_ANOMALY:f,NORAD_CAT_ID:s,EPHEMERIS_TYPE:O,BSTAR:g,MEAN_MOTION_DOT:T,MEAN_MOTION_DDOT:_,CLASSIFICATION_TYPE:a,ELEMENT_SET_NO:u,REV_AT_EPOCH:t.getRevNumberAtEpoch(o,!0),OBJECT_NAME:n?.OBJECT_NAME??"99999",OBJECT_ID:n?.OBJECT_ID??"99999",...n}}function S(e){const t=C(e),n=new Date(t.EPOCH),r=n.getUTCFullYear().toString().slice(-2).padStart(2,"0"),i=new Date(Date.UTC(n.getUTCFullYear(),0,1)),o=((n.getTime()-i.getTime())/864e5+1).toFixed(8).padStart(12,"0");let s="1 "+t.NORAD_CAT_ID.toString().padStart(5," ");s+=t.CLASSIFICATION_TYPE,s+=" "+(t.OBJECT_ID?.padEnd(8," ")||"00000AAA "),s+=" "+r+o;const a=t.MEAN_MOTION_DOT;s+=" "+Number(a).toFixed(8).padStart(9,"0");const c=t.MEAN_MOTION_DDOT;s+=" "+y(Number(c),5);s+=" "+y(Number(t.BSTAR),5),s+=" "+t.EPHEMERIS_TYPE,s+=" "+t.ELEMENT_SET_NO.toString().padStart(4," ");const l=P(s);s+=l;let E="2 "+t.NORAD_CAT_ID.toString().padStart(5," ");E+=" "+Number(t.INCLINATION).toFixed(4).padStart(8," "),E+=" "+Number(t.RA_OF_ASC_NODE).toFixed(4).padStart(8," ");E+=" "+Math.abs(Number(t.ECCENTRICITY)).toFixed(7).slice(2).padStart(7,"0"),E+=" "+Number(t.ARG_OF_PERICENTER).toFixed(4).padStart(8," "),E+=" "+Number(t.MEAN_ANOMALY).toFixed(4).padStart(8," ");E+=" "+Number(t.MEAN_MOTION).toFixed(8).padStart(11,"0");E+=Number(t.REV_AT_EPOCH).toString().padStart(5," ");const T=P(E);return E+=T,{line1:s,line2:E,checksum1:l,checksum2:T,omm:t}}function D(e){const t=I(e.semimajorAxis);let n=e.epoch.replaceAll(" ","T");n=n.endsWith("Z")?n:n+"Z";return S({EPOCH:n,MEAN_MOTION:t.revPerDay,ECCENTRICITY:e.eccentricity,INCLINATION:e.inclination,RA_OF_ASC_NODE:e.raan,ARG_OF_PERICENTER:e.argPerigee,MEAN_ANOMALY:e.meanAnomaly,...e.OMMInputForce})}function y(e,t){if(0===e)return" 00000-0";const n=e.toExponential(t).match(/^(-?)(\d+\.\d+)e([+-]\d+)$/i);if(!n)return" 00000-0";const[,r,i,o]=n,s=i.replace(".","").substring(0,t),a=Number.parseInt(o);return("-"===r?"-":" ")+s+(a>=0?"+":"-")+Math.abs(a).toString().padStart(1,"0")}function P(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];"-"===r?t+=1:!Number.isNaN(Number.parseInt(r))&&(t+=Number.parseInt(r))}return t%10}async function R(t,c={isGetDetails:!1,isUseGPU:!1}){try{const T=Date.now();let _;return _=c?.isUseGPU?await async function(t,c={isGetDetails:!1,isUseGPU:!0}){const T=Date.now();await n({module_or_path:a}),E(["wasm首次加载:",(Date.now()-T)/1e3,"秒"]);const _=Array.isArray(t.kepler);let g,O;if(_){O=t.kepler;g=C(w(O))}else{const e=D(t.kepler);O=[e.line1,e.line2],g=e.omm}const u=g.EPOCH.replaceAll(" ","T"),N=t.startTime.replaceAll(" ","T"),p=t.stopTime.replaceAll(" ","T"),m=new Date(u.endsWith("Z")?u:u+"Z").getTime(),A=new Date(N.endsWith("Z")?N:N+"Z").getTime()-m,f=new Date(p.endsWith("Z")?p:p+"Z").getTime()-m,I=t.step,d=A/1e3,h=f/1e3,M=Math.floor((h-d)/I)+1,S=new Float64Array(M);for(let e=0;e<M;e++){const t=d+e*I;S[e]=t/60}let y;try{y=await r.new_for_web()}catch{try{y=await r.new_for_web_gl()}catch(b){l("THROW","❌ WebGPU 不可用",b)}}const P=g.OBJECT_NAME||"Unknown";let R;try{R=i.from_tle((new TextEncoder).encode(P),(new TextEncoder).encode(O[0]),(new TextEncoder).encode(O[1]))}catch(H){l("THROW",["TLE 解析失败:\n",O[0]+"\n",O[1]+"\n"],H)}const L=o.from_elements(R),G=new Float32Array(6*M),F=5e4;for(let e=0;e<M;e+=F){const t=Math.min(e+F,M),n=t-e,r=Array.from({length:n}).map(()=>s.from_constants(L)),i=S.slice(e,t),o=await y.propagate_batch_f32(r,i);G.set(o,6*e)}const U=Array.from({length:M});for(let n=0;n<M;n++){const t=6*n,r={x:G[t],y:G[t+1],z:G[t+2]},i=new Date(m+1e3*(d+n*I));if(c.isGetDetails){const o=e.gstime(i),s={x:G[t+3],y:G[t+4],z:G[t+5]},a=e.eciToEcf(r,o),c=e.eciToEcf(s,o),l=e.eciToGeodetic(r,o),E={lat:e.degreesLat(l.latitude),lng:e.degreesLong(l.longitude),alt:1e3*l.height};U[n]={time:i.toISOString(),positionEci:r,positionEcf:a,velocityEci:s,velocityEcf:c,position:E}}else U[n]={time:i.toISOString(),positionEci:r}}return U}(t,c):await async function(t,n={isGetDetails:!1,isUseGPU:!1}){const r=Array.isArray(t.kepler);let i,o;if(r){i=e.twoline2satrec(t.kepler[0],t.kepler[1]);o=C(w(t.kepler)),d(o.MEAN_MOTION)}else{o=D(t.kepler).omm,i=e.json2satrec(o)}const s=o.EPOCH.replaceAll(" ","T"),a=t.startTime.replaceAll(" ","T"),c=t.stopTime.replaceAll(" ","T"),l=new Date(s.endsWith("Z")?s:s+"Z").getTime(),E=new Date(a.endsWith("Z")?a:a+"Z").getTime()-l,T=new Date(c.endsWith("Z")?c:c+"Z").getTime()-l,_=t.step,g=[],O=T/1e3;let u,N;for(let p=E/1e3;p<=O;p+=_){const t=e.sgp4(i,Number((p/60).toFixed(3)));if(t){u=new Date(l+1e3*p),N=e.gstime(u);const r=t.position;if(n.isGetDetails){const n=e.eciToEcf(r,N),i=e.eciToGeodetic(r,N),o=t.velocity,s=e.eciToEcf(o,N),a={lat:e.degreesLat(i.latitude),lng:e.degreesLong(i.longitude),alt:1e3*i.height};Reflect.deleteProperty(t.meanElements,"nm"),g.push({time:u.toISOString(),positionEci:r,positionEcf:n,velocityEci:o,velocityEcf:s,position:a,meanElements:t.meanElements})}else g.push({time:u.toISOString(),positionEci:r})}}return g}(t,c),E(["sgp4耗时:",(Date.now()-T)/1e3,"秒"]),_}catch(T){l("THROW","sgp4Orbit函数运行异常",T)}}async function L(c,T={isGetDetails:!1,isUseGPU:!0}){try{const _=Date.now();let g;return g=T?.isUseGPU?await async function(c,T={isGetDetails:!1,isUseGPU:!0}){let _=!1,g=null,O=null,u=!1;const N=/* @__PURE__ */new Map,p=[],m=[];let A=/* @__PURE__ */new Map,f=[],I=[],d=[];async function h(){if(_)return!0;try{await n({module_or_path:a});try{g=await r.new_for_web()}catch{g=await r.new_for_web_gl()}if(!g)return l("THROW","❌ GPU 传播器创建失败"),!1;const T=[];d=[];for(let n=0;n<c.length;n++){const r=c[n],{kepler:s,id:a}=r;let E,_;if(Array.isArray(s))[E,_]=s;else{const e=D(s);E=e.line1,_=e.line2}try{const e=t.parseTLE([E,_]),s=t.getEpochTimestamp(e);d.push(s);const l=i.from_tle((new TextEncoder).encode(String(r.id)),(new TextEncoder).encode(E),(new TextEncoder).encode(_)),g=o.from_elements(l);T.push(g),N.set(a,{epochTimestamp:s}),p.push(a),m.push(c[n])}catch(e){l("NOT_THROW",["TLE 解析失败:\n",E+"\n",_+"\n"],e);continue}}return I=T.map(e=>s.from_constants(e)),O=g.register_const_set(I),A=/* @__PURE__ */new Map,f=Array.from({length:m.length}),_=!0,E(["GPU 批处理初始化完成,卫星数量: "+m.length]),!0}catch(T){return l("THROW","GPU 初始化失败",T),!1}}async function C(t){if(_&&g&&null!==O&&!u){u=!0;try{const n=new Float64Array(m.length);for(let e=0;e<m.length;e++){const r=N.get(p[e]);if(r){const i=M(t,r.epochTimestamp);n[e]=i}else n[e]=0}const r=await g.propagate_registered_f32(O,n),i=Array.from({length:m.length});for(let s=0;s<m.length;s++){const n=6*s,o={x:r[n],y:r[n+1],z:r[n+2]},a=new Date(t);if(T.isGetDetails){const t=e.gstime(a),c={x:r[n+3],y:r[n+4],z:r[n+5]},l=e.eciToEcf(o,t),E=e.eciToEcf(c,t),T=e.eciToGeodetic(o,t);i[s]={time:a.toISOString(),positionEci:o,positionEcf:l,velocityEci:c,velocityEcf:E,position:{lat:e.degreesLat(T.latitude),lng:e.degreesLong(T.longitude),alt:1e3*T.height}}}else i[s]={time:a.toISOString(),positionEci:o}}f=i;const o=/* @__PURE__ */new Map;for(let e=0;e<m.length;e++)o.set(p[e],f[e]);return A=o,A}catch(n){return void console.error("GPU 更新错误:",n)}finally{u=!1}}}function w(){return A}function S(e){return A.get(e)}function y(){return _}function P(){return u}async function R(){if(_){if(_=!1,g&&null!==O){try{g.unregister_const_set(O)}catch(e){l("NOT_THROW","释放 GPU 常量集失败",e)}g=null,O=null}A.clear(),f=[],N.clear(),E(["GPU 批处理内存占用已清理"])}}return await h(),{dispose:R,isProcessing:P,isInitialized:y,getCurrentPositions:w,getPosition:S,update:C}}(c,T):await async function(n,r={isGetDetails:!1,isUseGPU:!1}){let i=!1,o=!1;const s=/* @__PURE__ */new Map,a=[],c=[];let T=/* @__PURE__ */new Map,_=[];async function g(){if(i)return!0;try{for(let r=0;r<n.length;r++){const i=n[r],{kepler:o,id:E}=i;let T,_;if(Array.isArray(o)){const[n,r]=o;T=e.twoline2satrec(n,r);const i=t.parseTLE([n,r]);_=t.getEpochTimestamp(i)}else{const t=D(o).omm;T=e.json2satrec(t);const n=t.EPOCH.replaceAll(" ","T");_=new Date(n.endsWith("Z")?n:n+"Z").getTime()}T&&!T.error?(s.set(E,{epochTimestamp:_,satrec:T}),a.push(E),c.push(i)):l("NOT_THROW","卫星 "+E+" TLE 解析失败: "+T?.error,new Error("SatRec error: "+T?.error))}return 0===c.length?(l("THROW","没有可用的卫星数据"),!1):(T=/* @__PURE__ */new Map,_=Array.from({length:c.length}),i=!0,E(["CPU 批处理初始化完成,卫星数量: "+c.length]),!0)}catch(r){return l("THROW","CPU 批处理初始化失败",r),!1}}async function O(t){if(i&&!o){o=!0;try{const n=Array.from({length:c.length});for(let o=0;o<c.length;o++){const i=a[o],c=s.get(i);if(!c)continue;const l=(t-c.epochTimestamp)/6e4,E=e.sgp4(c.satrec,l);if(!E)continue;const T=E.position,_=new Date(t);if(r.isGetDetails){const t=e.gstime(_),r=E.velocity,i=e.eciToEcf(T,t),s=e.eciToEcf(r,t),a=e.eciToGeodetic(T,t);Reflect.deleteProperty(E.meanElements,"nm"),n[o]={time:_.toISOString(),positionEci:T,positionEcf:i,velocityEci:r,velocityEcf:s,position:{lat:e.degreesLat(a.latitude),lng:e.degreesLong(a.longitude),alt:1e3*a.height},meanElements:E.meanElements}}else n[o]={time:_.toISOString(),positionEci:T}}_=n;const i=/* @__PURE__ */new Map;for(let e=0;e<c.length;e++)_[e]&&i.set(a[e],_[e]);return T=i,T}catch(n){return void console.error("CPU 更新错误:",n)}finally{o=!1}}}function u(){return T}function N(e){return T.get(e)}function p(){return i}function m(){return o}async function A(){i&&(i=!1,T.clear(),_=[],s.clear(),E(["CPU 批处理内存占用已清理"]))}return await g(),{dispose:A,isProcessing:m,isInitialized:p,getCurrentPositions:u,getPosition:N,update:O}}(c,T),E(["sgp4耗时:",(Date.now()-_)/1e3,"秒"]),g}catch(_){l("THROW","sgp4OrbitLive函数运行异常",_)}}export{e as _satellitejs,t as _tlejs,C as getFullOmm,I as getMeanMotion,M as getMinutesSinceEpoch,h as getPeriod,d as getSemiMajorAxis,R as sgp4Orbit,L as sgp4OrbitLive,D as transKeplerToTle,S as transOmmToTle,w as transTleToOmm};
|
package/dist/stats.html
CHANGED
|
@@ -4930,7 +4930,7 @@ var drawChart = (function (exports) {
|
|
|
4930
4930
|
</script>
|
|
4931
4931
|
<script>
|
|
4932
4932
|
/*<!--*/
|
|
4933
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"kbe3d-satellite.js","children":[{"name":"D:/3-project/1-git/kbe3d/packages/satellite/src","children":[{"name":"internal/errorHandling.ts","uid":"
|
|
4933
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"kbe3d-satellite.js","children":[{"name":"D:/3-project/1-git/kbe3d/packages/satellite/src","children":[{"name":"internal/errorHandling.ts","uid":"62bb0b65-1"},{"name":"main","children":[{"uid":"62bb0b65-3","name":"utils.ts"},{"uid":"62bb0b65-5","name":"sgp4.ts"}]},{"uid":"62bb0b65-7","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"62bb0b65-1":{"renderedLength":410,"gzipLength":0,"brotliLength":0,"metaUid":"62bb0b65-0"},"62bb0b65-3":{"renderedLength":5780,"gzipLength":0,"brotliLength":0,"metaUid":"62bb0b65-2"},"62bb0b65-5":{"renderedLength":9286,"gzipLength":0,"brotliLength":0,"metaUid":"62bb0b65-4"},"62bb0b65-7":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"62bb0b65-6"}},"nodeMetas":{"62bb0b65-0":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/internal/errorHandling.ts","moduleParts":{"kbe3d-satellite.js":"62bb0b65-1"},"imported":[],"importedBy":[{"uid":"62bb0b65-4"},{"uid":"62bb0b65-2"}]},"62bb0b65-2":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/main/utils.ts","moduleParts":{"kbe3d-satellite.js":"62bb0b65-3"},"imported":[{"uid":"62bb0b65-9"},{"uid":"62bb0b65-0"}],"importedBy":[{"uid":"62bb0b65-6"},{"uid":"62bb0b65-4"}]},"62bb0b65-4":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/main/sgp4.ts","moduleParts":{"kbe3d-satellite.js":"62bb0b65-5"},"imported":[{"uid":"62bb0b65-8"},{"uid":"62bb0b65-11"},{"uid":"62bb0b65-12"},{"uid":"62bb0b65-9"},{"uid":"62bb0b65-0"},{"uid":"62bb0b65-2"}],"importedBy":[{"uid":"62bb0b65-6"}]},"62bb0b65-6":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/index.ts","moduleParts":{"kbe3d-satellite.js":"62bb0b65-7"},"imported":[{"uid":"62bb0b65-8"},{"uid":"62bb0b65-9"},{"uid":"62bb0b65-10"},{"uid":"62bb0b65-4"},{"uid":"62bb0b65-2"}],"importedBy":[],"isEntry":true},"62bb0b65-8":{"id":"satellite.js","moduleParts":{},"imported":[],"importedBy":[{"uid":"62bb0b65-6"},{"uid":"62bb0b65-4"}],"isExternal":true},"62bb0b65-9":{"id":"tle.js","moduleParts":{},"imported":[],"importedBy":[{"uid":"62bb0b65-6"},{"uid":"62bb0b65-4"},{"uid":"62bb0b65-2"}],"isExternal":true},"62bb0b65-10":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/helper.ts","moduleParts":{},"imported":[],"importedBy":[{"uid":"62bb0b65-6"}]},"62bb0b65-11":{"id":"sgp4.gl","moduleParts":{},"imported":[],"importedBy":[{"uid":"62bb0b65-4"}],"isExternal":true},"62bb0b65-12":{"id":"sgp4.gl/wasm?url","moduleParts":{},"imported":[],"importedBy":[{"uid":"62bb0b65-4"}],"isExternal":true}},"env":{"rollup":"4.59.0"},"options":{"gzip":false,"brotli":false,"sourcemap":false}};
|
|
4934
4934
|
|
|
4935
4935
|
const run = () => {
|
|
4936
4936
|
const width = window.innerWidth;
|