/** * Checks if the given point is a corner of this triangle. * * @param p * The given point. * @return True iff the given point is a corner of this triangle. * * By Eyal Roth & Doron Ganel. */ public boolean isCorner(Point p) { return (p.getX() == a.getX() && p.getY() == a.getY()) || (p.getX() == b.getX() && p.getY() == b.getY()) || (p.getX() == c.getX() && p.getY() == c.getY()); }
/** @return the L2 distanse NOTE: 2D only!!! */ public double distance(Point p) { double temp = Math.pow(p.getX() - x, 2) + Math.pow(p.getY() - y, 2); return Math.sqrt(temp); }
/** * @return The bounding rectange between the minimum and maximum coordinates * of the triangle */ public BoundingBox getBoundingBox() { Point lowerLeft, upperRight; lowerLeft = new Point(Math.min(a.getX(), Math.min(b.getX(), c.getX())), Math.min(a.getY(), Math.min(b.getY(), c.getY()))); upperRight = new Point(Math.max(a.getX(), Math.max(b.getX(), c.getX())), Math.max(a.getY(), Math.max(b.getY(), c.getY()))); return new BoundingBox(lowerLeft, upperRight); }
public static void exportCHTsin(DelaunayTriangulation dto, String tsinFile) throws IOException { FileWriter fw = new FileWriter(tsinFile); PrintWriter os = new PrintWriter(fw); // prints the tsin file header: os.println(dto.getConvexHullSize()); Iterator<Point> it = dto.getConvexHullVerticesIterator(); while (it.hasNext()) { Point p = it.next(); os.println(String.format("%s %s", p.getX(), p.getY())); } os.close(); fw.close(); }
/** @return the L2 distanse NOTE: 3D only!!! */ public double distance3D(Point p) { double temp = Math.pow(p.getX() - x, 2) + Math.pow(p.getY() - y, 2) + Math.pow(p.getZ() - z, 2); return Math.sqrt(temp); }
Circle circumcircle() { double u = ((a.getX() - b.getX()) * (a.getX() + b.getX()) + (a.getY() - b.getY()) * (a.getY() + b.getY())) / 2.0f; double v = ((b.getX() - c.getX()) * (b.getX() + c.getX()) + (b.getY() - c.getY()) * (b.getY() + c.getY())) / 2.0f; double den = (a.getX() - b.getX()) * (b.getY() - c.getY()) - (b.getX() - c.getX()) * (a.getY() - b.getY()); if (den == 0) // oops, degenerate case circum = new Circle(a, Double.POSITIVE_INFINITY); else { Point cen = new Point((u * (b.getY() - c.getY()) - v * (a.getY() - b.getY())) / den, (v * (a.getX() - b.getX()) - u * (b.getX() - c.getX())) / den); circum = new Circle(cen, cen.distance2(a)); } return circum; }
public static void exportTsin(DelaunayTriangulation dto, Writer writer) { PrintWriter os = new PrintWriter(writer); try { // prints the tsin file header: int len = dto.size(); os.println(len); Iterator<Point> it = dto.verticesIterator(); while (it.hasNext()) { Point p = it.next(); os.println(String.format("%s %s %s", p.getX(), p.getY(), p.getZ())); } } finally { Utils.closeQuietly(os); } }
/** * Create a bounding box between lowerLeft and upperRight * * @param lowerLeft * lower left point of the box * @param upperRight * upper left point of the box */ public BoundingBox(Point lowerLeft, Point upperRight) { init(lowerLeft.getX(), upperRight.getX(), lowerLeft.getY(), upperRight.getY(), lowerLeft.getZ(), upperRight.getZ()); }
/** * Finds a triangle near the given point * * @param point * a query point * @return a triangle at the same cell of the point */ public Triangle findCellTriangleOf(Point point) { int xIndex = (int) ((point.getX() - indexRegion.minX()) / xSize); int yIndex = (int) ((point.getY() - indexRegion.minY()) / ySize); return grid[xIndex][yIndex]; }
/** * compute the Z value for the X,Y values of q. assume this triangle * represent a plane --> q does NOT need to be contained in this triangle. * * @param q * query point (its Z value is ignored). * @return q with updated Z value. * */ public Point getZ(Point q) { double z = zValue(q); return new Point(q.getX(), q.getY(), z); }
public static Coord3d toJzyCoord(Point point) { return new Coord3d((float) point.getX(), (float)point.getY(), (float)point.getZ()); }
os.println(String.format("v %s %s %s", p.getX(), p.getY(), p.getZ()));
/** * returns an iterator to the set of all the points on the XY-convex hull * * @return iterator to the set of all the points on the XY-convex hull. */ public Iterator<Point> getConvexHullVerticesIterator() { Vector<Point> ans = new Vector<Point>(); Triangle curr = this.startTriangleHull; boolean cont = true; double x0 = bbMin.getX(), x1 = bbMax.getX(); double y0 = bbMin.getY(), y1 = bbMax.getY(); boolean sx, sy; while (cont) { sx = curr.getA().getX() == x0 || curr.getA().getX() == x1; sy = curr.getA().getY() == y0 || curr.getA().getY() == y1; if ((sx && sy) || (!sx && !sy)) { ans.add(curr.getA()); } if (curr.getBcTriangle() != null && curr.getBcTriangle().isHalfplane()) curr = curr.getBcTriangle(); if (curr == this.startTriangleHull) cont = false; } return ans.iterator(); }
/** * Locates the grid cell point covering the given coordinate * * @param coordinate * world coordinate to locate * @return cell covering the coordinate */ private PointInt getCellOf(Point coordinate) { int xCell = (int) ((coordinate.getX() - indexRegion.minX()) / xSize); int yCell = (int) ((coordinate.getY() - indexRegion.minY()) / ySize); return new PointInt(xCell, yCell); }
throw new RuntimeException("*** ERR wrong parameters, can't approximate the z value ..***: " + q); if (q.getX() == a.getX() && q.getY() == a.getY()) return a.getZ(); if (q.getX() == b.getX() && q.getY() == b.getY()) return b.getZ(); if (q.getX() == c.getX() && q.getY() == c.getY()) return c.getZ(); double X = 0, x0 = q.getX(), x1 = a.getX(), x2 = b.getX(), x3 = c.getX(); double Y = 0, y0 = q.getY(), y1 = a.getY(), y2 = b.getY(), y3 = c.getY(); double Z = 0, m01 = 0, k01 = 0, m23 = 0, k23 = 0;
private void updateBoundingBox(Point p) { double x = p.getX(), y = p.getY(), z = p.getZ(); if (bbMin == null) { bbMin = new Point(p); bbMax = new Point(p); } else { if (x < bbMin.getX()) bbMin.setX(x); else if (x > bbMax.getX()) bbMax.setX(x); if (y < bbMin.getY()) bbMin.setY(y); else if (y > bbMax.getY()) bbMax.setY(y); if (z < bbMin.getZ()) bbMin.setZ(z); else if (z > bbMax.getZ()) bbMax.setZ(z); } }
/ (halfplane.getA().getX() - halfplane.getB().getX()); double yOrient = halfplaneDelta * (third.getX() - halfplane.getA().getX()) + halfplane.getA().getY(); boolean above = true; if (yOrient > third.getY()) double xCellLine = (circumcircle.getX() + (500.0 * sign)); double yCellLine = perpDelta * (xCellLine - circumcircle.getX()) + circumcircle.getY();