/
OutputLayout.cs
87 lines (69 loc) · 1.93 KB
/
OutputLayout.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright Lamont Granquist, Sebastien Gaggini and the MechJeb contributors
* SPDX-License-Identifier: LicenseRef-PD-hp OR Unlicense OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT OR LGPL-2.1+
*/
#nullable enable
using System;
using System.Collections.Generic;
using MechJebLib.Primitives;
using MechJebLib.Utils;
namespace MechJebLib.PVG
{
public struct OutputLayout
{
public const int OUTPUT_LAYOUT_LEN = 15;
public V3 R;
public V3 V;
public V3 PV;
public V3 PR;
public double CostateMagnitude => Math.Sqrt(PR.sqrMagnitude + PV.sqrMagnitude);
public double M;
public double Pm;
public double H0
{
get
{
double rm = R.magnitude;
return V3.Dot(PR, V) -
V3.Dot(PV, R) / (rm * rm * rm); // FIXME: this changes for linear gravity model??!?!?
}
}
public double DV;
public OutputLayout(InputLayout other)
{
R = other.R;
V = other.V;
PV = other.PV;
PR = other.PR;
M = other.M;
Pm = other.Pm;
DV = 0;
}
public void CopyTo(IList<double> other)
{
R.CopyTo(other, 0);
V.CopyTo(other, 3);
PV.CopyTo(other, 6);
PR.CopyTo(other, 9);
other[12] = M;
other[13] = Pm;
other[14] = DV;
}
public void CopyFrom(IList<double> other)
{
R.CopyFrom(other, 0);
V.CopyFrom(other, 3);
PV.CopyFrom(other, 6);
PR.CopyFrom(other, 9);
M = other[12];
Pm = other[13];
DV = other[14];
}
public static OutputLayout CreateFrom(IList<double> other)
{
var a = new OutputLayout();
a.CopyFrom(other);
return a;
}
}
}