/** * @param north - how far north we are * @param east - how far east we are * @param height the height */ public LocalLocation( final WorldDistance north, final WorldDistance east, final WorldDistance height) { super( north.getValueIn(WorldDistance.DEGS), east.getValueIn(WorldDistance.DEGS), -height.getValueIn(WorldDistance.METRES)); }
public final void testPerpDistanceFrom() { WorldLocation.setModel(new CompletelyFlatEarth()); final WorldLocation me = new WorldLocation(7, 0, 0); final WorldLocation p1 = new WorldLocation(4, 4, 0); WorldLocation p2 = new WorldLocation(12, 4, 0); WorldDistance res = me.perpendicularDistanceBetween(p1, p2); assertEquals("off-track error is correct", 4.0, res.getValueIn(WorldDistance.DEGS), 0.001); p2 = new WorldLocation(9, 2, 0); res = me.perpendicularDistanceBetween(p1, p2); assertEquals("off-track error is correct", 2.5997, res.getValueIn(WorldDistance.DEGS), 0.001); p2 = new WorldLocation(-4, -4, 0); res = me.perpendicularDistanceBetween(p1, p2); assertEquals("off-track error is correct", 4.9497, res.getValueIn(WorldDistance.DEGS), 0.001); res = me.rangeFrom(p1, p2); assertEquals( "off-track error is correct (using range from operator)", 4.9497, res.getValueIn(WorldDistance.DEGS), 0.001); }
/** * subtract the two points to produce a vector * * @param other the offset to add to this point * @return a new point */ public final WorldDistance rangeFrom(final WorldLocation other, final WorldDistance res) { // check we have our model if (_model == null) { _model = new MWC.Algorithms.EarthModels.FlatEarth(); } // ok, how far apart are they? final WorldVector sep = _model.subtract(other, this); // update the results object res.setValues(sep.getRange(), WorldDistance.DEGS); // and return it. return res; }
/** long winded constructor, taking raw arguments */ public LocalLocation( final int latDegs, final int latMin, final double latSec, final char latHem, final int longDegs, final int longMin, final double longSec, final char longHem, final WorldDistance height) { super( latDegs, latMin, latSec, latHem, longDegs, longMin, longSec, longHem, -height.getValueIn(WorldDistance.METRES)); }
public final void setPatternBuoySpacing(WorldDistance val) { _spacing = val.getValueIn(WorldDistance.NM); }
/** * @param lat the latitude * @param longVal the longitude * @param height the height */ public LocalLocation(final double lat, final double longVal, final WorldDistance height) { super(lat, longVal, -height.getValueIn(WorldDistance.METRES)); }
/** put our keywords into the XML description */ protected static String swapKeywords( final DetectionEvent detection, final Status currentLocation, final String weapon, final TargetType theTarget) { // amend string template to include available parameters final Float brg_degs = detection.getBearing(); final WorldDistance rng = detection.getRange(); // take a copy of the string String working = new String(weapon); // swap the bearing if (brg_degs != null) { final String brg_val = "" + brg_degs.floatValue(); working = replaceAll(working, "$BRG$", brg_val); } // swap the range if (rng != null) { final String rng_val = "" + rng.getValueIn(WorldDistance.YARDS); working = replaceAll(working, "$RNG$", rng_val); } // insert the location of the target if (brg_degs != null) { final float brg_val = brg_degs.floatValue(); // do we know range? if (rng != null) { // yes, compute target location final WorldVector newVector = new WorldVector( MWC.Algorithms.Conversions.Degs2Rads(brg_val), rng.getValueIn(WorldDistance.DEGS), 0); final WorldLocation newLoc = currentLocation.getLocation().add(newVector); // produce strings from this location final String theDepth = "" + newLoc.getDepth(); final String theLat = "" + newLoc.getLat(); final String theLong = "" + newLoc.getLong(); // put these strings into the new behaviour working = replaceAll(working, "$TGT_DEPTH$", theDepth); working = replaceAll(working, "$TGT_LAT$", theLat); working = replaceAll(working, "$TGT_LONG$", theLong); } else { // no, send the weapon down a bearing for XXXX yds // compute target location final double TGT_RANGE = 5000; final WorldVector newVector = new WorldVector( MWC.Algorithms.Conversions.Degs2Rads(brg_val), MWC.Algorithms.Conversions.Yds2Degs(TGT_RANGE), 0); final WorldLocation newLoc = currentLocation.getLocation().add(newVector); // produce strings from this location final String theDepth = "" + newLoc.getDepth(); final String theLat = "" + newLoc.getLat(); final String theLong = "" + newLoc.getLong(); // put these strings into the new behaviour working = replaceAll(working, "$TGT_DEPTH$", theDepth); working = replaceAll(working, "$TGT_LAT$", theLat); working = replaceAll(working, "$TGT_LONG$", theLong); } } if (theTarget != null) { // output the XML header stuff // output the plot final java.io.StringWriter newString = new StringWriter(); // final com.sun.xml.tree.XmlDocument doc = new com.sun.xml.tree.XmlDocument(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc = null; try { DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); final org.w3c.dom.Element type = ASSET.Util.XML.Decisions.Util.TargetTypeHandler.getElement(theTarget, doc); doc.appendChild(type); doc.setNodeValue(type.getTagName()); // doc.changeNodeOwner(type); // doc.setSystemId("ASSET XML Version 1.0"); // Use a Transformer for output TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(newString); transformer.transform(source, result); } catch (ParserConfigurationException e) { e.printStackTrace(); // To change body of catch statement use Options | File Templates. } catch (DOMException e) { e.printStackTrace(); // To change body of catch statement use Options | File Templates. } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) { transformerFactoryConfigurationError .printStackTrace(); // To change body of catch statement use Options | File Templates. } catch (TransformerException e) { e.printStackTrace(); // To change body of catch statement use Options | File Templates. } // // ok, we should be done now // try // { // doc.write(newString); // } // catch(java.io.IOException e) // { // e.printStackTrace(); // } // try to extract the <target type portion if (newString != null) { final String val = newString.toString(); final String startIdentifier = "<TargetType"; final String endIdentifier = "</TargetType"; final int start = val.indexOf(startIdentifier); final int end = val.lastIndexOf(endIdentifier); final String detail = val.substring(start, end + endIdentifier.length() + 1); // lastly, replace the string working = replaceAll(working, "<TargetType/>", detail); } } return working; }
/** * decide the course of action to take, or return null to no be used * * @param status the current status of the participant * @param detections the current list of detections for this participant * @param time the time this decision was made */ public DemandedStatus decide( final Status status, ASSET.Models.Movement.MovementCharacteristics chars, DemandedStatus demStatus, final DetectionList detections, final ASSET.Scenario.ScenarioActivityMonitor monitor, final long time) { // produce a steady-state demanded course - so we continue // what we're doing during the weapons launch DemandedStatus res = null; // clear the activity flag String activity = "Not in trail"; // is it time to fire another yet? if ((_lastLaunch == -1) || (time > _lastLaunch + _coolOffTime.getValueIn(Duration.MILLISECONDS))) { // do we have any detections? if (detections != null) { // get bearing to first detection final int len = detections.size(); if (len > 0) { for (int i = 0; i < len; i++) { final ASSET.Models.Detection.DetectionEvent de = detections.getDetection(i); final Float brg = de.getBearing(); if (brg != null) { // do we have a target type? if (_myTarget != null) { // is this of our target type final ASSET.Participants.Category thisTarget = de.getTargetType(); if (_myTarget.matches(thisTarget)) { // do we have range? if (de.getRange() != null) { // work out distance from us to the target, not from the sensor to the target WorldLocation sensorLocation = de.getSensorLocation(); // Work out the estimated target location WorldVector sensorToTarget = new WorldVector( MWC.Algorithms.Conversions.Degs2Rads(de.getBearing().doubleValue()), de.getRange().getValueIn(WorldDistance.DEGS), 0); WorldLocation targetLocation = sensorLocation.add(sensorToTarget); // how are are we from the target location WorldVector meToTarget = status.getLocation().subtract(targetLocation); double yds_to_target = MWC.Algorithms.Conversions.Degs2Yds(meToTarget.getRange()); double brg_to_target_degs = MWC.Algorithms.Conversions.Rads2Degs(meToTarget.getBearing()); // is it within range? if (yds_to_target < _launchRange.getValueIn(WorldDistance.YARDS)) { // continue in steady state res = new SimpleDemandedStatus(time, status); // remember the launch time _lastLaunch = time; // start the launch steps launchWeapon(de, monitor, status, brg_to_target_degs, time); activity = LaunchWeapon.LAUNCH_MESSAGE; // ok, drop out, we don't need to launch any more weapons return res; } } } } } // if we know the bearing } // looping through the detections } // if we have any detections } // if the detections object was received } // whether it's time to launch another else { // } super.setLastActivity(activity); // always return null, since we continue in steady state return res; }