The missile knows where it is at all times
It knows this because it knows where it isn't
function draw(){
...
// Update target's position based on velocity
targetPosition.add(targetVelocity.mult(targetSpeed));
...
}
The above line of code updates the missile with the current position of the target position, aka the position where the missile isn't at.
By subtracting where it is from where it isn't,
or where it isn't from where it is (whichever is greater),
it obtains a difference, or deviation
function draw(){
...
// Calculate difference, or deviation
const subtracted = p5.Vector.sub(targetPosition, missilePosition);
const deviation = deviation.mag();
...
}
We now use a function to subtract where the missile is (missilePosition), from where it isn't (targetPosition), to obtain a difference.
We take the absolute value of it, as it is a workaround that achieves the same result as subtracting whichever is greater from whichever is smaller
The guidance subsystem uses deviations to generate corrective commands to drive the missile from a
position where
it is to a position where it isn't,
and arriving at a position where it wasn't, it now is
function draw(){
...
if (!missilePaused) {
const direction = p5.Vector.sub(targetPosition, missilePosition);
missileAngle = direction.heading();
direction.normalize();
missilePosition.add(direction.mult(missileSpeed));
}
...
}
This chunk of code corrects the angle of the missile to make it point from where it is to where it isn't, and thereafter it pushes the missile towards the position where it wasn't such that it now is in the position where it now is
Consequently, the position where it is,
is now the position that it wasn't,
and it follows that the position that it was,
is now the position that it isn't
function draw(){
...
previousMissilePosition = missilePosition.copy();
...
}
The position where it was (missilePosition), is now the position that it isn't (previousMissilePosition)
In the event that the position that it is in is not the position that it wasn't, the system has acquired a variation,
the variation being the difference between where the missile is, and where it wasn't
If variation is considered to be a significant factor,
it too may be corrected by the GEA
However, the missile must also know where it was
The missile guidance computer scenario works as follows
Because a variation has modified some of the information the missile has obtained,
it is not sure just where it is
However, it is sure where it isn't, within reason, and it knows where it was
It now subtracts where it should be from where it wasn't, or vice-versa,
and by differentiating this from the algebraic sum of where it shouldn't be, and where it was,
it is able to obtain the deviation and its variation, which is called error
The code required can be obtained from using straightforward application of knowledge of missile guidance and control systems
A detailed proof of statement unfortunately exceeds the scope of this explanation.
The derivation of the code required from the problem statement as given above is too long to present here, but it can be worked out using a symbolic computation system such as Mathematica.
The code required follows from a straightforward application of the basic fundamentals of missile guidance and control systems; we refer the reader to existing literature on the topic for details of this.