kbe3d-satellite 0.0.1 → 0.0.3
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 +17 -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,12 @@ 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?: Omit<KeplerElements, 'epoch' | 'OMMInputForce'>;
|
|
396
402
|
}
|
|
397
403
|
|
|
398
404
|
/**
|
|
@@ -500,15 +506,7 @@ export { _satellitejs }
|
|
|
500
506
|
* - isGetDetails: 是否获取更多详细信息,默认为false
|
|
501
507
|
* - isUseGPU: 是否使用GPU计算,默认为false
|
|
502
508
|
*
|
|
503
|
-
* @returns
|
|
504
|
-
* - satrec: 解析后的卫星记录对象,包含轨道参数
|
|
505
|
-
* - result: 包含时间、ECF坐标、ECI坐标、速度和地理坐标的数组
|
|
506
|
-
* 每个结果项包含:
|
|
507
|
-
* - time: 对应时刻的ISO格式时间戳
|
|
508
|
-
* - positionEcf: 地固坐标系中的位置向量
|
|
509
|
-
* - positionEci: 惯性坐标系中的位置向量
|
|
510
|
-
* - velocityEci: 惯性坐标系中的速度向量
|
|
511
|
-
* - position: 地理坐标(纬度、经度、高度)
|
|
509
|
+
* @returns 返回包含卫星记录和位置结果数组的对象
|
|
512
510
|
*/
|
|
513
511
|
export declare function sgp4Orbit(params: OrbitPropagatorParams, config?: OrbitPropagatorConfig): Promise<OrbitPropagatorResult[] | undefined>;
|
|
514
512
|
|
|
@@ -542,6 +540,16 @@ export declare function transKeplerToTle(kepler: KeplerElements): {
|
|
|
542
540
|
omm: _satellitejs.OMMJsonObjectV3;
|
|
543
541
|
};
|
|
544
542
|
|
|
543
|
+
/**
|
|
544
|
+
* 将卫星的平均轨道根数(MeanElements)转换为开普勒轨道要素(KeplerElements)
|
|
545
|
+
* 此函数排除了 epoch 和 OMMInputForce 属性
|
|
546
|
+
*
|
|
547
|
+
* @param o - 输入的卫星平均轨道根数对象,类型为 satellite.MeanElements
|
|
548
|
+
* @returns 返回转换后的开普勒轨道要素对象,类型为 Omit<KeplerElements, 'epoch' | 'OMMInputForce'>,
|
|
549
|
+
* 包含半长轴、偏心率、倾角、升交点赤经、近地点幅角和平均近点角
|
|
550
|
+
*/
|
|
551
|
+
export declare function transMeanElements(o: _satellitejs.MeanElements): Omit<KeplerElements, "epoch" | "OMMInputForce">;
|
|
552
|
+
|
|
545
553
|
/**
|
|
546
554
|
* 将OMM格式对象转换为TLE格式
|
|
547
555
|
* @param input - OMM输入对象
|
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 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,u=0,O="U",m=99999,A=9999,N=99999,p="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 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??u,CLASSIFICATION_TYPE:e.CLASSIFICATION_TYPE??O,NORAD_CAT_ID:e.NORAD_CAT_ID??m,ELEMENT_SET_NO:e.ELEMENT_SET_NO??A,REV_AT_EPOCH:e.REV_AT_EPOCH??N,OBJECT_NAME:e.OBJECT_NAME??p,OBJECT_ID:e.OBJECT_ID??f}}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),u=Number.parseInt(i.substring(62,63).trim()||"0"),O=t.getTleSetNumber(o,!0),m=t.getInclination(o,!0),A=t.getRightAscension(o,!0),N=t.getEccentricity(o,!0),p=t.getPerigee(o,!0),f=t.getMeanAnomaly(o,!0);return{EPOCH:E,MEAN_MOTION:t.getMeanMotion(o,!0),ECCENTRICITY:N,INCLINATION:m,RA_OF_ASC_NODE:A,ARG_OF_PERICENTER:p,MEAN_ANOMALY:f,NORAD_CAT_ID:s,EPHEMERIS_TYPE:u,BSTAR:g,MEAN_MOTION_DOT:T,MEAN_MOTION_DDOT:_,CLASSIFICATION_TYPE:a,ELEMENT_SET_NO:O,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+=" "+P(Number(c),5);s+=" "+P(Number(t.BSTAR),5),s+=" "+t.EPHEMERIS_TYPE,s+=" "+t.ELEMENT_SET_NO.toString().padStart(4," ");const l=R(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=R(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){const t=180/Math.PI;return{semimajorAxis:6378137*e.am,eccentricity:e.em,inclination:e.im*t,raan:e.Om*t,argPerigee:e.om*t,meanAnomaly:e.mm*t}}function P(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 R(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 L(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,u;if(_){u=t.kepler;g=C(w(u))}else{const e=D(t.kepler);u=[e.line1,e.line2],g=e.omm}const O=g.EPOCH.replaceAll(" ","T"),m=t.startTime.replaceAll(" ","T"),A=t.stopTime.replaceAll(" ","T"),N=new Date(O.endsWith("Z")?O:O+"Z").getTime(),p=new Date(m.endsWith("Z")?m:m+"Z").getTime()-N,f=new Date(A.endsWith("Z")?A:A+"Z").getTime()-N,I=t.step,h=p/1e3,d=f/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(u[0]),(new TextEncoder).encode(u[1]))}catch(H){l("THROW",["TLE 解析失败:\n",u[0]+"\n",u[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(N+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=[],u=T/1e3;let O,m;for(let A=E/1e3;A<=u;A+=_){const t=e.sgp4(r,Number((A/60).toFixed(3)));if(t){O=new Date(l+1e3*A),m=e.gstime(O);const i=t.position;if(n.isGetDetails){const n=e.eciToEcf(i,m),r=e.eciToGeodetic(i,m),o=t.velocity,s=e.eciToEcf(o,m),a={lat:e.degreesLat(r.latitude),lng:e.degreesLong(r.longitude),alt:1e3*r.height},c=y(t.meanElements);g.push({time:O.toISOString(),positionEci:i,positionEcf:n,velocityEci:o,velocityEcf:s,position:a,meanElements:c})}else g.push({time:O.toISOString(),positionEci:i})}}return g}(t,c),E(["sgp4耗时:",(Date.now()-T)/1e3,"秒"]),_}catch(T){l("THROW","sgp4Orbit函数运行异常",T)}}async function G(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,u=null,O=!1;const m=/* @__PURE__ */new Map,A=[],N=[];let p=/* @__PURE__ */new Map,f=[],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),m.set(a,{epochTimestamp:s}),A.push(a),N.push(c[n])}catch(e){l("NOT_THROW",["TLE 解析失败:\n",E+"\n",_+"\n"],e);continue}}return I=T.map(e=>s.from_constants(e)),u=g.register_const_set(I),p=/* @__PURE__ */new Map,f=Array.from({length:N.length}),_=!0,E(["GPU 批处理初始化完成,卫星数量: "+N.length]),!0}catch(T){return l("THROW","GPU 初始化失败",T),!1}}async function C(t){if(_&&g&&null!==u&&!O){O=!0;try{const n=new Float64Array(N.length);for(let e=0;e<N.length;e++){const i=m.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(u,n),r=Array.from({length:N.length});for(let s=0;s<N.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}}f=r;const o=/* @__PURE__ */new Map;for(let e=0;e<N.length;e++)o.set(A[e],f[e]);return p=o,p}catch(n){return void console.error("GPU 更新错误:",n)}finally{O=!1}}}function w(){return p}function S(e){return p.get(e)}function y(){return _}function P(){return O}async function R(){if(_){if(_=!1,g&&null!==u){try{g.unregister_const_set(u)}catch(e){l("NOT_THROW","释放 GPU 常量集失败",e)}g=null,u=null}p.clear(),f=[],m.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 u(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),c=y(E.meanElements);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},meanElements:c}}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 O(){return T}function m(e){return T.get(e)}function A(){return r}function N(){return o}async function p(){r&&(r=!1,T.clear(),_=[],s.clear(),E(["CPU 批处理内存占用已清理"]))}return await g(),{dispose:p,isProcessing:N,isInitialized:A,getCurrentPositions:O,getPosition:m,update:u}}(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,L as sgp4Orbit,G as sgp4OrbitLive,D as transKeplerToTle,y as transMeanElements,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":"f44b9f61-1"},{"name":"main","children":[{"uid":"f44b9f61-3","name":"utils.ts"},{"uid":"f44b9f61-5","name":"sgp4.ts"}]},{"uid":"f44b9f61-7","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"f44b9f61-1":{"renderedLength":410,"gzipLength":0,"brotliLength":0,"metaUid":"f44b9f61-0"},"f44b9f61-3":{"renderedLength":5996,"gzipLength":0,"brotliLength":0,"metaUid":"f44b9f61-2"},"f44b9f61-5":{"renderedLength":9232,"gzipLength":0,"brotliLength":0,"metaUid":"f44b9f61-4"},"f44b9f61-7":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"f44b9f61-6"}},"nodeMetas":{"f44b9f61-0":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/internal/errorHandling.ts","moduleParts":{"kbe3d-satellite.js":"f44b9f61-1"},"imported":[],"importedBy":[{"uid":"f44b9f61-4"},{"uid":"f44b9f61-2"}]},"f44b9f61-2":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/main/utils.ts","moduleParts":{"kbe3d-satellite.js":"f44b9f61-3"},"imported":[{"uid":"f44b9f61-9"},{"uid":"f44b9f61-0"}],"importedBy":[{"uid":"f44b9f61-6"},{"uid":"f44b9f61-4"}]},"f44b9f61-4":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/main/sgp4.ts","moduleParts":{"kbe3d-satellite.js":"f44b9f61-5"},"imported":[{"uid":"f44b9f61-8"},{"uid":"f44b9f61-11"},{"uid":"f44b9f61-12"},{"uid":"f44b9f61-9"},{"uid":"f44b9f61-0"},{"uid":"f44b9f61-2"}],"importedBy":[{"uid":"f44b9f61-6"}]},"f44b9f61-6":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/index.ts","moduleParts":{"kbe3d-satellite.js":"f44b9f61-7"},"imported":[{"uid":"f44b9f61-8"},{"uid":"f44b9f61-9"},{"uid":"f44b9f61-10"},{"uid":"f44b9f61-4"},{"uid":"f44b9f61-2"}],"importedBy":[],"isEntry":true},"f44b9f61-8":{"id":"satellite.js","moduleParts":{},"imported":[],"importedBy":[{"uid":"f44b9f61-6"},{"uid":"f44b9f61-4"}],"isExternal":true},"f44b9f61-9":{"id":"tle.js","moduleParts":{},"imported":[],"importedBy":[{"uid":"f44b9f61-6"},{"uid":"f44b9f61-4"},{"uid":"f44b9f61-2"}],"isExternal":true},"f44b9f61-10":{"id":"D:/3-project/1-git/kbe3d/packages/satellite/src/helper.ts","moduleParts":{},"imported":[],"importedBy":[{"uid":"f44b9f61-6"}]},"f44b9f61-11":{"id":"sgp4.gl","moduleParts":{},"imported":[],"importedBy":[{"uid":"f44b9f61-4"}],"isExternal":true},"f44b9f61-12":{"id":"sgp4.gl/wasm?url","moduleParts":{},"imported":[],"importedBy":[{"uid":"f44b9f61-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;
|