void construct(PlanningSegment seg, WorldLocation origin, HiResDate date) { // check we have some data if (date == null || origin == null) return; double timeTravelledMillis = getSecsTravelled(seg) * 1000; // ditch the existing items seg.removeAllElements(); // ok build for this segment double courseDegs = seg.getCourse(); double courseRads = MWC.Algorithms.Conversions.Degs2Rads(courseDegs); long timeMillis = date.getDate().getTime(); final long timeStepMillis; final long ONE_MIN = 60 * 1000; final long ONE_HOUR = 60 * ONE_MIN; final long ONE_DAY = 24 * ONE_HOUR; // use a time step appropriate to how long we're generating the track for if (timeTravelledMillis <= 4 * ONE_HOUR) timeStepMillis = ONE_MIN; else if (timeTravelledMillis <= 12 * ONE_HOUR) timeStepMillis = 10 * ONE_MIN; else if (timeTravelledMillis <= 2 * ONE_DAY) timeStepMillis = 30 * ONE_MIN; else timeStepMillis = ONE_HOUR; // now work out how far he will have travelled in a time step double distPerMinute = getMinuteDelta(seg); double distPerStep = distPerMinute * (timeStepMillis / ONE_MIN); WorldVector vec = new WorldVector(courseRads, new WorldDistance(distPerStep, WorldDistance.METRES), null); for (long tNow = timeMillis; tNow <= timeMillis + timeTravelledMillis; tNow += timeStepMillis) { HiResDate thisDtg = new HiResDate(tNow); // ok, do this fix Fix thisF = new Fix(thisDtg, origin, courseRads, seg.getSpeed().getValueIn(WorldSpeed.ft_sec) / 3); // override the depth thisF.getLocation().setDepth(seg.getDepth().getValueIn(WorldDistance.METRES)); FixWrapper fw = new FixWrapper(thisF); fw.setColor(seg.getColor()); // and store it seg.add(fw); // reset the name, we're not going to use a human generated one fw.resetName(); // produce a new position origin = origin.add(vec); } }
@Override double getMinuteDelta(PlanningSegment seg) { // how far will we travel in time? double metresPerSec = seg.getSpeed().getValueIn(WorldSpeed.M_sec); double metresPerMin = metresPerSec * 60d; double distanceM = metresPerSec * getSecsTravelled(seg); WorldDistance wd = new WorldDistance(distanceM, WorldDistance.METRES); seg.setDistanceSilent(new WorldDistance(wd.getValueIn(WorldDistance.NM), WorldDistance.NM)); return metresPerMin; }
@Override protected double getSecsTravelled(PlanningSegment seg) { // how long does it take to travel this distance? double secsTaken = seg.getDistance().getValueIn(WorldDistance.METRES) / seg.getSpeed().getValueIn(WorldSpeed.M_sec); // sort out the leg length seg.setDurationSilent(new Duration(secsTaken, Duration.SECONDS)); return secsTaken; }
@Override double getMinuteDelta(PlanningSegment seg) { // find out how far it travels double distPerMinute = seg.getSpeed().getValueIn(WorldSpeed.M_sec) * 60d; return distPerMinute; }