mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(cockpit): the bridge radar matches the view out of the window
The radar centred on the ship's last AIS fix while the camera rode that fix dead-reckoned up to 180 s ahead: at 20 kn about a nautical mile apart, so a ship already passed still showed ahead. Own ship now sits where the camera rides and each contact is dead-reckoned to the same moment; the query reaches past the range for ships that have since moved into it. Ships with no MMSI each get a key of their own instead of all sharing an empty one on the scope.
This commit is contained in:
1 parent
18c15d0352
commit
052731202d
9 files changed
+154
-29
No files matched your search
@@ -9,6 +9,10 @@ import {
|
||||
relativeBearing,
|
||||
} from './cockpitMath.js';
|
||||
import { greatCircleMeters } from './geoDistance.js';
|
||||
import {
|
||||
deadReckonVesselFix,
|
||||
VESSEL_DEAD_RECKON_MAX_S,
|
||||
} from './cockpitSubjects.js';
|
||||
|
||||
/** Metres in one international nautical mile. */
|
||||
export const METRES_PER_NM = 1852;
|
||||
@@ -22,6 +26,14 @@ export const DEFAULT_RADAR_RANGE_NM = 3;
|
||||
/** At most this many contacts are drawn, nearest first. */
|
||||
export const RADAR_MAX_CONTACTS = 60;
|
||||
|
||||
/**
|
||||
* How far past the range a contact's last fix can lie and still be in range
|
||||
* once dead-reckoned: the projection limit at 40 kn, faster than all but a
|
||||
* few high-speed craft.
|
||||
*/
|
||||
export const RADAR_REACH_M =
|
||||
VESSEL_DEAD_RECKON_MAX_S * 40 * (METRES_PER_NM / 3600);
|
||||
|
||||
/** Range rings divide the range into this many equal steps. */
|
||||
export const RADAR_RING_COUNT = 4;
|
||||
|
||||
@@ -68,6 +80,36 @@ export function radarRangeM(rangeNm) {
|
||||
|
||||
const round4 = (value) => Math.round(value * 1e4) / 1e4;
|
||||
|
||||
/**
|
||||
* Advance each contact's last fix along its course over ground to `nowMs`,
|
||||
* as the bridge camera advances its own ship, so own ship and contacts are
|
||||
* drawn at the same moment. A contact with no direction stays on its fix.
|
||||
* @param {Array<object>} contacts Contacts with the `vesselCockpitInfo`
|
||||
* motion fields (`motionCourse`, `velocityMps`, `fixEpochMs`,
|
||||
* `receivedAtMs`, `feedEpochMs`).
|
||||
* @param {number} nowMs Client clock, ms.
|
||||
* @returns {Array<object>} The contacts with dead-reckoned positions.
|
||||
*/
|
||||
export function deadReckonRadarContacts(contacts, nowMs) {
|
||||
if (!Array.isArray(contacts)) return [];
|
||||
return contacts.map((contact) => {
|
||||
if (!Number.isFinite(contact?.motionCourse)) return contact;
|
||||
const fix = deadReckonVesselFix(
|
||||
{
|
||||
latitude: contact.latitude,
|
||||
longitude: contact.longitude,
|
||||
courseDeg: contact.motionCourse,
|
||||
speedMps: contact.velocityMps,
|
||||
fixEpochMs: contact.fixEpochMs,
|
||||
receivedAtMs: contact.receivedAtMs,
|
||||
feedEpochMs: contact.feedEpochMs,
|
||||
},
|
||||
nowMs,
|
||||
);
|
||||
return { ...contact, latitude: fix.latitude, longitude: fix.longitude };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Project vessel contacts onto a heading-up radar.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user