/** * work out the perpendicular distance between me and the supplied line segment * * @param lineStart start point of the line * @param lineEnd end point of the line * @return perpendicular distance off track. */ protected WorldDistance perpendicularDistanceBetween( final WorldLocation lineStart, final WorldLocation lineEnd) { final Point2D pStart = new Point2D.Double(lineStart.getLong(), lineStart.getLat()); final Point2D pEnd = new Point2D.Double(lineEnd.getLong(), lineEnd.getLat()); final Point2D tgt = new Point2D.Double(this.getLong(), this.getLat()); final double res = distanceToSegment(pStart, pEnd, tgt); final WorldDistance distance = new WorldDistance(res, WorldDistance.DEGS); // Note: we were using an algorithm to calculate the dist to a point on a // continuous line, not // a line segment. The above code class the correct algorithm. // // sort out known angles // double thetaOne = lineEnd.bearingFrom(lineStart); // double thetaTwo = Math.PI - lineStart.bearingFrom(this); // double thetaThree = thetaOne + thetaTwo; // // // and the single known distance // double rangeToP1 = lineStart.rangeFrom(this); // // // now do our trig. // double sinThetaThree = Math.abs(Math.sin(thetaThree)); // WorldDistance distance = new WorldDistance(rangeToP1 * sinThetaThree, // WorldDistance.DEGS); // sorted. return distance; }
/** * create a new point that is this point rotated by set radians about the supplied axis * * @param pOrigin centre of rotation * @param brg angle rotated through (radians) * @return new location */ public final WorldLocation rotatePoint(final WorldLocation pOrigin, final double brg) { final double resLong = pOrigin.getLong() + (Math.cos((brg)) * (this.getLong() - pOrigin.getLong()) - Math.sin(brg) * (this.getLat() - pOrigin.getLat())); final double resLat = pOrigin.getLat() + (Math.sin((brg)) * (this.getLong() - pOrigin.getLong()) + Math.cos(brg) * (this.getLat() - pOrigin.getLat())); final WorldLocation res = new WorldLocation(resLat, resLong, 0d); return res; }
public final void setXXX() { final double dep = w4.getDepth(); final double dLat = w4.getLat(); final double dLong = w4.getLong(); w1.setDepth(dep); w1.setLat(dLat); w1.setLong(dLong); assertTrue(w1.equals(w4)); }
public void testDecimalConstructor() { // test the secs component WorldLocation worldLoc = new WorldLocation(22, 0, 45, 'N', 22, 0, 1.45, 'W', 0); assertEquals("right lat", 22.0125, worldLoc.getLat(), 0.001); assertEquals("right long", -22.000402, worldLoc.getLong(), 0.00001); // now the mins component worldLoc = new WorldLocation(22, 0.5, 00, 'N', 14, 0.5, 0, 'W', 0); assertEquals("right lat", 22.008, worldLoc.getLat(), 0.01); assertEquals("right long", -14.008333, worldLoc.getLong(), 0.00001); // now the degs component worldLoc = new WorldLocation(22.5, 0, 00, 'N', 14.5, 0, 0, 'W', 0); assertEquals("right lat", 22.5, worldLoc.getLat(), 0.01); assertEquals("right long", -14.5, worldLoc.getLong(), 0.00001); // // NOW LET'S REVERSE THE HEMISPHERE // test the secs component worldLoc = new WorldLocation(22, 0, 45, 'S', 22, 0, 1.45, 'E', 0); assertEquals("right lat", -22.0125, worldLoc.getLat(), 0.001); assertEquals("right long", 22.000402, worldLoc.getLong(), 0.00001); // now the mins component worldLoc = new WorldLocation(22, 0.5, 00, 'S', 14, 0.5, 0, 'E', 0); assertEquals("right lat", -22.008, worldLoc.getLat(), 0.01); assertEquals("right long", 14.008333, worldLoc.getLong(), 0.00001); // now the degs component worldLoc = new WorldLocation(22.5, 0, 00, 'S', 14.5, 0, 0, 'E', 0); assertEquals("right lat", -22.5, worldLoc.getLat(), 0.01); assertEquals("right long", 14.5, worldLoc.getLong(), 0.00001); }
/** * note that addToMe changes this object * * @param delta the offset to add to this point */ public void addToMe(final WorldVector delta) { // check we have our model if (_model == null) { _model = new MWC.Algorithms.EarthModels.FlatEarth(); } // do the calculation with our model final WorldLocation res = _model.add(this, delta); // update ourselves to the result setLat(res.getLat()); setLong(res.getLong()); setDepth(res.getDepth()); }
public final void testGetLong() { assertEquals(w1.getLong(), 12.4, 0d); }
/** 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; }