List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Line distance
public double distance(final Line line)
From source file:org.orekit.attitudes.TargetPointingTest.java
/** Test if defined target belongs to the direction pointed by the satellite *//*w w w . j a v a 2s . co m*/ @Test public void testTargetInPointingDirection() throws OrekitException { // Create computation date AbsoluteDate date = new AbsoluteDate(new DateComponents(2008, 04, 07), TimeComponents.H00, TimeScalesFactory.getUTC()); // Reference frame = ITRF 2005 Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true); // Elliptic earth shape OneAxisEllipsoid earthShape = new OneAxisEllipsoid(6378136.460, 1 / 298.257222101, itrf); // Create target pointing attitude provider GeodeticPoint geoTarget = new GeodeticPoint(FastMath.toRadians(43.36), FastMath.toRadians(1.26), 600.); TargetPointing targetAttitudeLaw = new TargetPointing(FramesFactory.getEME2000(), geoTarget, earthShape); // Satellite position // ******************** // Create satellite position as circular parameters CircularOrbit circ = new CircularOrbit(7178000.0, 0.5e-4, -0.5e-4, FastMath.toRadians(50.), FastMath.toRadians(270.), FastMath.toRadians(5.300), PositionAngle.MEAN, FramesFactory.getEME2000(), date, mu); // Transform satellite position to position/velocity parameters in EME2000 frame PVCoordinates pvSatEME2000 = circ.getPVCoordinates(); // Pointing direction // ******************** // Get satellite attitude rotation, i.e rotation from EME2000 frame to satellite frame Rotation rotSatEME2000 = targetAttitudeLaw.getAttitude(circ, date, circ.getFrame()).getRotation(); // Transform Z axis from satellite frame to EME2000 Vector3D zSatEME2000 = rotSatEME2000.applyInverseTo(Vector3D.PLUS_K); // Line containing satellite point and following pointing direction Vector3D p = eme2000ToItrf.transformPosition(pvSatEME2000.getPosition()); Line pointingLine = new Line(p, p.add(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, eme2000ToItrf.transformVector(zSatEME2000)), 1.0e-10); // Check that the line contains earth center double distance = pointingLine.distance(earthShape.transform(geoTarget)); Assert.assertEquals(0, distance, 1.e-7); }
From source file:org.orekit.frames.TransformTest.java
@Test public void testLine() { RandomGenerator random = new Well19937a(0x4a5ff67426c5731fl); for (int i = 0; i < 100; ++i) { Transform transform = randomTransform(random); for (int j = 0; j < 20; ++j) { Vector3D p0 = randomVector(1.0e3, random); Vector3D p1 = randomVector(1.0e3, random); Line l = new Line(p0, p1, 1.0e-10); Line transformed = transform.transformLine(l); for (int k = 0; k < 10; ++k) { Vector3D p = l.pointAt(random.nextDouble() * 1.0e6); Assert.assertEquals(0.0, transformed.distance(transform.transformPosition(p)), 1.0e-9); }/*from w ww. jav a2s. c om*/ } } }
From source file:tests.TestDrawing.java
@Test public void testDrawing() { BufferedImage img = null;//from w w w . j a va 2 s. c o m BufferedImage imgs[] = new BufferedImage[2]; try { imgs[0] = ImageIO.read(new File("../captures/4.jpg")); // eventually C:\\ImageTest\\pic2.jpg imgs[1] = ImageIO.read(new File("../captures/5.jpg")); // eventually C:\\ImageTest\\pic2.jpg img = ImageIO.read(new File("../captures/5.jpg")); // eventually C:\\ImageTest\\pic2.jpg for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { int rgbDiff = RgbCalculator.absoluteDifference(imgs[0].getRGB(x, y), imgs[1].getRGB(x, y)); img.setRGB(x, y, rgbDiff); } } Graphics2D g2d = img.createGraphics(); g2d.setBackground(Color.BLUE); g2d.setColor(Color.RED); Vector3D[] corners = new Vector3D[] { new Vector3D(new double[] { 172, 78, 0 }), new Vector3D(new double[] { 455, 71, 0 }), new Vector3D(new double[] { 507, 350, 0 }), new Vector3D(new double[] { 143, 362, 0 }) }; //draw lines from corner to corner for (int c = 0; c < corners.length; c++) { Vector3D v1 = corners[c]; Vector3D v2 = corners[(c + 1) % corners.length]; g2d.drawLine((int) v1.getX(), (int) v1.getY(), (int) v2.getX(), (int) v2.getY()); } for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { Vector3D currentPos = new Vector3D(new double[] { x, y, 0 }); double[] normalizedCoordinates = new double[2]; { //normalize x coordinate Line floor = new Line(corners[0], corners[3], 0.5); Line roof = new Line(corners[1], corners[2], 0.5); double floorDistance = floor.distance(currentPos) * 1 / corners[0].distance(corners[3]); double roofDistance = roof.distance(currentPos) * 1 / corners[1].distance(corners[2]); normalizedCoordinates[0] = interpolate(0, 1, floorDistance / (floorDistance + roofDistance)); } { //normalize y coordinate Line floor = new Line(corners[0], corners[1], 0.5); Line roof = new Line(corners[2], corners[3], 0.5); double floorDistance = floor.distance(currentPos) * 1 / corners[0].distance(corners[1]); double roofDistance = roof.distance(currentPos) * 1 / corners[2].distance(corners[3]); normalizedCoordinates[1] = interpolate(0, 1, floorDistance / (floorDistance + roofDistance)); } boolean isEdge = false; for (int d = 0; d < 2; d++) { double val = normalizedCoordinates[d]; if (Math.abs((double) ((int) (val * 8)) - (val * 8)) < 0.05) { isEdge = true; } } if (isEdge) { //color corners red: img.setRGB(x, y, Color.RED.getRGB()); } } } JFrame dialog = new JFrame(); ImagePanel imagePanel = new ImagePanel(img); dialog.add(imagePanel); imagePanel.setSize(100, 100); dialog.pack(); dialog.setSize(300, 300); dialog.setVisible(true); } catch (IOException e) { throw new RuntimeException(e); } assertTrue("hello", true); }