ready to write task4
This commit is contained in:
40
A/4/simulator.py
Normal file
40
A/4/simulator.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from loong import *
|
||||
import json
|
||||
class BestOrbit(Orbit):
|
||||
def __init__(self):
|
||||
self.kAlpha = mp.mpf('1.7') / (2 * mp.pi)
|
||||
def InitIdx(self):
|
||||
return mp.mpf('0.0')
|
||||
def InitC(self):
|
||||
return mp.mpf('0.0')
|
||||
def Idx2C(self, idx):
|
||||
return idx / self.kAlpha
|
||||
def Idx2Cartesian(self, idx):
|
||||
return mp.matrix([mp.cos(idx), mp.sin(idx)])
|
||||
def C2Idx(self, C):
|
||||
return C * self.kAlpha
|
||||
def GenerateNextPointIdx(self, cur_point_idx, expected_distance):
|
||||
return cur_point_idx + expected_distance
|
||||
|
||||
if __name__ == "__main__":
|
||||
orbit=BestOrbit()
|
||||
loong=Loong(orbit, 224, mp.mpf('2.0'), mp.mpf('1e-8'))
|
||||
res_list=[]
|
||||
for ti in range(-100,101):
|
||||
print(f"calculating time_point={ti}")
|
||||
res_list.append(loong.CalcStatusListByTime(mp.mpf(ti)))
|
||||
# 转换成内置浮点数并保留6位
|
||||
float_res_list = [
|
||||
[
|
||||
{
|
||||
"idx": round(float(node["idx"]),6),
|
||||
"node": [round(float(node["node"][0]),6), round(float(node["node"][1]),6)],
|
||||
"C": round(float(node["C"]),6),
|
||||
"v": round(float(node["v"]),6)
|
||||
}
|
||||
for node in res
|
||||
]
|
||||
for res in res_list
|
||||
]
|
||||
with open("A4_res.json", "w") as file:
|
||||
json.dump(float_res_list, file, indent=4)
|
Reference in New Issue
Block a user