Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * R e a d m e
- * -----------
- *
- * In this file you can include any instructions or other comments you want to have injected onto the
- * top of your final script. You can safely delete this file if you do not want any such comments.
- */
- // cpa_time(): compute the time of CPA for two tracks
- // Input: two tracks Tr1 and Tr2
- // Return: the time at which the two tracks are closest
- public static double cpa_time(Vector3D Tr1_p, Vector3D Tr1_v, Vector3D Tr2_p, Vector3D Tr2_v)
- {
- Vector3D dv = Tr1_v - Tr2_v;
- double dv2 = Vector3D.Dot(dv, dv);
- if (dv2 < 0.00000001) // the tracks are almost parallel
- return 0.0; // any time is ok. Use time 0.
- Vector3D w0 = Tr1_p - Tr2_p;
- double cpatime = -Vector3D.Dot(w0, dv) / dv2;
- return cpatime; // time of CPA
- }
- public static string Vector2GPSString(string l, Vector3D v)
- {
- //GPS: klassekatze #2:4186.55:17490.12:19153.15:#FFB775F1:
- return "GPS:" + l + ":" + v.X.ToString("0.00") + ":" + v.Y.ToString("0.00") + ":" + v.Z.ToString("0.00") + ":#FFB775F1:";
- }
- IMyShipController c = null;
- public Program()
- {
- c = (IMyShipController)GridTerminalSystem.GetBlockWithName("Cockpit");
- }
- Vector3D p1, p2 = Vector3D.Zero;
- Vector3D g1, g2 = Vector3D.Zero;
- public void Main(string argument, UpdateType updateSource)
- {
- if (argument == "m")
- {
- if (p1 == Vector3D.Zero)
- {
- p1 = c.GetPosition();
- g1 = Vector3D.Normalize(c.GetNaturalGravity());
- }
- else if (p2 == Vector3D.Zero)
- {
- p2 = c.GetPosition();
- g2 = Vector3D.Normalize(c.GetNaturalGravity());
- }
- if (p2 != Vector3D.Zero)
- {
- double t = cpa_time(p1, g1, p2, g2);
- if (t != 0.0)
- {
- Vector3D center = p1 + (g1 * t);
- string o = t + "\n" + g1.ToString()+"\n"+g2.ToString()+"\n"+
- Vector2GPSString("pcenter", center);
- Me.CustomData = o;
- Echo(o);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement