/** * Compute the position of a sprite if it is not attached. * * @param sprite The sprite. * @param pos Where to stored the computed position, if null, the position is created. * @param units The units the computed position must be given into. * @return The same instance as pos, or a new one if pos was null. */ protected Point2D.Double getSpritePositionFree( GraphicSprite sprite, Point2D.Double pos, Units units) { if (pos == null) pos = new Point2D.Double(); if (sprite.getUnits() == units) { pos.x = sprite.getX(); pos.y = sprite.getY(); } else if (units == Units.GU && sprite.getUnits() == Units.PX) { pos.x = sprite.getX(); pos.y = sprite.getY(); xT.transform(pos, pos); } else if (units == Units.PX && sprite.getUnits() == Units.GU) { pos.x = sprite.getX(); pos.y = sprite.getY(); Tx.transform(pos, pos); } else if (units == Units.GU && sprite.getUnits() == Units.PERCENTS) { pos.x = metrics.lo.x + (sprite.getX() / 100f) * metrics.graphWidthGU(); pos.y = metrics.lo.y + (sprite.getY() / 100f) * metrics.graphHeightGU(); } else if (units == Units.PX && sprite.getUnits() == Units.PERCENTS) { pos.x = (sprite.getX() / 100f) * metrics.viewport[2]; pos.y = (sprite.getY() / 100f) * metrics.viewport[3]; } else { throw new RuntimeException("Unhandled yet sprite positioning."); } return pos; }
/** * Compute the position of a sprite if attached to an edge. * * @param sprite The sprite. * @param pos Where to stored the computed position, if null, the position is created. * @param units The units the computed position must be given into. * @return The same instance as pos, or a new one if pos was null. */ protected Point2D.Double getSpritePositionEdge( GraphicSprite sprite, Point2D.Double pos, Units units) { if (pos == null) pos = new Point2D.Double(); GraphicEdge edge = sprite.getEdgeAttachment(); if (edge.isCurve()) { double ctrl[] = edge.getControlPoints(); Point2 p0 = new Point2(edge.from.getX(), edge.from.getY()); Point2 p1 = new Point2(ctrl[0], ctrl[1]); Point2 p2 = new Point2(ctrl[1], ctrl[2]); Point2 p3 = new Point2(edge.to.getX(), edge.to.getY()); Vector2 perp = CubicCurve.perpendicular(p0, p1, p2, p3, sprite.getX()); double y = metrics.lengthToGu(sprite.getY(), sprite.getUnits()); perp.normalize(); perp.scalarMult(y); pos.x = CubicCurve.eval(p0.x, p1.x, p2.x, p3.x, sprite.getX()) - perp.data[0]; pos.y = CubicCurve.eval(p0.y, p1.y, p2.y, p3.y, sprite.getX()) - perp.data[1]; } else { double x = ((GraphicNode) edge.getSourceNode()).x; double y = ((GraphicNode) edge.getSourceNode()).y; double dx = ((GraphicNode) edge.getTargetNode()).x - x; double dy = ((GraphicNode) edge.getTargetNode()).y - y; double d = sprite.getX(); // Percent on the edge. double o = metrics.lengthToGu(sprite.getY(), sprite.getUnits()); // Offset from the position given by percent, perpendicular to the // edge. d = d > 1 ? 1 : d; d = d < 0 ? 0 : d; x += dx * d; y += dy * d; d = (double) Math.sqrt(dx * dx + dy * dy); dx /= d; dy /= d; x += -dy * o; y += dx * o; pos.x = x; pos.y = y; if (units == Units.PX) { Tx.transform(pos, pos); } } return pos; }
public Point2D.Double projectInverse(double xyx, double xyy, Point2D.Double lp) { double c; xyy /= C_y; c = Math.cos(lp.y = tan_mode ? Math.atan(xyy) : MapMath.asin(xyy)); lp.x = xyx / (C_x * Math.cos(lp.y /= C_p)); if (tan_mode) { lp.x /= c * c; } else { lp.x *= c; } return lp; }
/** * Subdivides this Cubic curve into two curves at t = 0.5. can be done with getSegment but this is * more efficent. * * @param c0 if non-null contains portion of curve from 0->.5 * @param c1 if non-null contains portion of curve from .5->1 */ public void subdivide(Cubic c0, Cubic c1) { if ((c0 == null) && (c1 == null)) return; double npX = (p1.x + 3 * (p2.x + p3.x) + p4.x) * 0.125; double npY = (p1.y + 3 * (p2.y + p3.y) + p4.y) * 0.125; double npdx = ((p2.x - p1.x) + 2 * (p3.x - p2.x) + (p4.x - p3.x)) * 0.125; double npdy = ((p2.y - p1.y) + 2 * (p3.y - p2.y) + (p4.y - p3.y)) * 0.125; if (c0 != null) { c0.p1.x = p1.x; c0.p1.y = p1.y; c0.p2.x = (p2.x + p1.x) * 0.5; c0.p2.y = (p2.y + p1.y) * 0.5; c0.p3.x = npX - npdx; c0.p3.y = npY - npdy; c0.p4.x = npX; c0.p4.y = npY; } if (c1 != null) { c1.p1.x = npX; c1.p1.y = npY; c1.p2.x = npX + npdx; c1.p2.y = npY + npdy; c1.p3.x = (p4.x + p3.x) * 0.5; c1.p3.y = (p4.y + p3.y) * 0.5; c1.p4.x = p4.x; c1.p4.y = p4.y; } }
/** * Subdivides this Cubic curve into two curves at given t. * * @param c0 if non-null contains portion of curve from 0->t. * @param c1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Cubic c0, Cubic c1) { if ((c0 == null) && (c1 == null)) return; Point2D.Double np = eval(t); Point2D.Double npd = evalDt(t); if (c0 != null) { c0.p1.x = p1.x; c0.p1.y = p1.y; c0.p2.x = (p2.x + p1.x) * t; c0.p2.y = (p2.y + p1.y) * t; c0.p3.x = np.x - (npd.x * t / 3); c0.p3.y = np.y - (npd.y * t / 3); c0.p4.x = np.x; c0.p4.y = np.y; } if (c1 != null) { c1.p1.x = np.x; c1.p1.y = np.y; c1.p2.x = np.x + (npd.x * (1 - t) / 3); c1.p2.y = np.y + (npd.y * (1 - t) / 3); c1.p3.x = (p4.x + p3.x) * (1 - t); c1.p3.y = (p4.y + p3.y) * (1 - t); c1.p4.x = p4.x; c1.p4.y = p4.y; } }
public GeneralPath transform(GeneralPath in) { GeneralPath out = new GeneralPath(); PathIterator it = in.getPathIterator(null); float[] seg = new float[6]; Point2D.Double din = new Point2D.Double(); Point2D.Double dout = new Point2D.Double(); while (!it.isDone()) { int l = it.currentSegment(seg); din.x = seg[0]; din.y = seg[1]; projection.transform(din, dout); float x = (float) dout.x - minx; float y = maxy - (float) dout.y; try { if (!projection.inside(din.x, din.y)) l = PathIterator.SEG_MOVETO; } catch (Exception e) { l = PathIterator.SEG_MOVETO; } if (l == PathIterator.SEG_MOVETO) { out.moveTo(x, y); } else { out.lineTo(x, y); } it.next(); } return out; }
@Override public List<GeoEventPage> getNextFrame() { List<GeoEventPage> list = new ArrayList<GeoEventPage>(); if (Math.random() <= 0.9) { currentCycle++; return list; } for (int j = 0; j < 5; j++) { Point2D.Double newPoint; if (Math.random() <= 0.05) { newPoint = addNewSeedPoint(); } else { Point2D.Double randomSeedPoint = seedPoints.get((int) (Math.random() * seedPoints.size())); newPoint = new Point.Double(randomSeedPoint.x, randomSeedPoint.y); double distance = (Math.random() * ((CumulativeGeoFrameRenderer.LONGITUDE_DEGREES / 10))); newPoint.x += (Math.random() * distance) - (distance / 2); newPoint.y += (Math.random() * distance) - (distance / 2); } GeoEventPage randomPage = new GeoEventPage(newPoint.x, newPoint.y, currentCycle, 0, 0, 0, ""); list.add(randomPage); } currentCycle++; return list; }
public static Utility.Pair<ArrayList<Double>, ArrayList<Double>> calcFacingEdges( Point2D.Double position, Hashtable<ArrayList<Point2D.Double>, ArrayList<Point2D.Double>> obstacleToNormals) { ArrayList<Point2D.Double> lineStartPoints = new ArrayList<Point2D.Double>(); ArrayList<Point2D.Double> lineEndPoints = new ArrayList<Point2D.Double>(); Point2D.Double pointToLineEndpoint = new Point2D.Double(); for (Entry<ArrayList<Double>, ArrayList<Double>> e : obstacleToNormals.entrySet()) { ArrayList<Double> obstacle = e.getKey(); ArrayList<Double> normals = e.getValue(); Point2D.Double lineStartPoint = obstacle.get(0); int numNormals = normals.size(); for (int i = 0; i < normals.size(); ++i) { Point2D.Double n = normals.get(i); pointToLineEndpoint.x = lineStartPoint.x - position.x; pointToLineEndpoint.y = lineStartPoint.y - position.y; double dot = n.x * pointToLineEndpoint.x + n.y * pointToLineEndpoint.y; Point2D.Double lineEndPoint = obstacle.get((i + 1) % numNormals); if (dot < 0) { lineStartPoints.add(lineStartPoint); lineEndPoints.add(lineEndPoint); } lineStartPoint = lineEndPoint; } } return new Utility.Pair<ArrayList<Point2D.Double>, ArrayList<Point2D.Double>>( lineStartPoints, lineEndPoints); }
/** * Check if a sprite contains the given point (x,y). * * @param elt The sprite. * @param x The point abscissa. * @param y The point ordinate. * @return True if (x,y) is in the given element. */ protected boolean spriteContains(GraphicElement elt, double x, double y) { Values size = elt.getStyle().getSize(); double w2 = metrics.lengthToPx(size, 0) / 2; double h2 = size.size() > 1 ? metrics.lengthToPx(size, 1) / 2 : w2; Point2D.Double dst = spritePositionPx((GraphicSprite) elt); // new // Point2D.Double( // elt.getX(), // elt.getY() // ); // Point2D.Double dst = new Point2D.Double(); // Tx.transform( src, dst ); dst.x -= metrics.viewport[0]; dst.y -= metrics.viewport[1]; double x1 = dst.x - w2; double x2 = dst.x + w2; double y1 = dst.y - h2; double y2 = dst.y + h2; if (x < x1) return false; if (y < y1) return false; if (x > x2) return false; if (y > y2) return false; return true; }
private Point2D getBezier( double percent, Point2D.Double C1, Point2D.Double C2, Point2D.Double C3, Point2D.Double C4) { Point2D.Double pos = new Point2D.Double(); pos.x = C1.x * B1(percent) + C2.x * B2(percent) + C3.x * B3(percent) + C4.x * B4(percent); pos.y = C1.y * B1(percent) + C2.y * B2(percent) + C3.y * B3(percent) + C4.y * B4(percent); return pos; }
private void draw(Graphics2D g2, Point2D cursor, double width, double height) { double widthFactor = 0.95f; double heightFactor = 0.95f; double yAxeWidth = width - (width * widthFactor); double xAxeHeight = height - height * heightFactor; Point2D.Double localCursor = new Point2D.Double(cursor.getX(), cursor.getY()); localCursor.x += yAxeWidth; plot.draw(g2, localCursor, width * widthFactor, height * heightFactor); Range plotYRange = plot.getPlotModel().getYRange(); AxisState yAxisState = yAxis.build(g2, cursor, yAxeWidth, height * heightFactor, plot.getPlotArea(), plotYRange); localCursor.y += height * heightFactor; Range plotXRange = plot.getPlotModel().getXRange(); AxisState xAxisState = xAxis.build( g2, localCursor, width * widthFactor, xAxeHeight, plot.getPlotArea(), plotXRange); synFontSize(xAxisState, yAxisState); xAxis.draw(); yAxis.draw(); gridRenderer.draw(g2, plot.getPlotArea(), xAxisState, yAxisState); }
public Point2D.Double project(double lplam, double lpphi, Point2D.Double xy) { double c; xy.x = C_x * lplam * Math.cos(lpphi); xy.y = C_y; lpphi *= C_p; c = Math.cos(lpphi); if (tan_mode) { xy.x *= c * c; xy.y *= Math.tan(lpphi); } else { xy.x /= c; xy.y *= Math.sin(lpphi); } return xy; }
public Point2D.Double projectInverse(double xyx, double xyy, Point2D.Double out) { double t = 0; double lpphi = RYC * xyy; if (Math.abs(lpphi) > 1.) { if (Math.abs(lpphi) > ONETOL) { throw new ProjectionException("I"); } else if (lpphi < 0.) { t = -1.; lpphi = -Math.PI; } else { t = 1.; lpphi = Math.PI; } } else { lpphi = 2. * Math.asin(t = lpphi); } out.x = RXC * xyx / (1. + 2. * Math.cos(lpphi) / Math.cos(0.5 * lpphi)); lpphi = RC * (t + Math.sin(lpphi)); if (Math.abs(lpphi) > 1.) { if (Math.abs(lpphi) > ONETOL) { throw new ProjectionException("I"); } else { lpphi = lpphi < 0. ? -MapMath.HALFPI : MapMath.HALFPI; } } else { lpphi = Math.asin(lpphi); } out.y = lpphi; return out; }
/* CENTROID */ public static Point2D.Double polygonCenterOfMass(Point2D.Double[] polygon) { int N = polygon.length - 1; double cx = 0, cy = 0; // double A = signedPolygonArea(polygon); Point2D.Double res = new Point2D.Double(); int i, j; double sumDet = 0; double factor = 0; for (i = 0; i < N; i++) { j = i + 1; factor = (polygon[i].x * polygon[j].y - polygon[j].x * polygon[i].y); cx += (polygon[i].x + polygon[j].x) * factor; cy += (polygon[i].y + polygon[j].y) * factor; sumDet += factor; } factor = 1 / (3 * sumDet); // A*=6.0; // factor=1/A; cx *= factor; cy *= factor; res.x = cx; res.y = cy; return res; }
public final void updateMousePos(double xRW, double yRW) { if (isVisible) { // double xRW = view.toRealWorldCoordX(mx); // double yRW = view.toRealWorldCoordY(my); int mx = view.toScreenCoordX(xRW); int my = view.toScreenCoordY(yRW); // round angle to nearest 15 degrees if alt pressed if (points.size() == 1 && view.getEuclidianController().altDown) { GeoPoint p = (GeoPoint) points.get(0); double px = p.inhomX; double py = p.inhomY; double angle = Math.atan2(yRW - py, xRW - px) * 180 / Math.PI; double radius = Math.sqrt((py - yRW) * (py - yRW) + (px - xRW) * (px - xRW)); // round angle to nearest 15 degrees angle = Math.round(angle / 15) * 15; xRW = px + radius * Math.cos(angle * Math.PI / 180); yRW = py + radius * Math.sin(angle * Math.PI / 180); mx = view.toScreenCoordX(xRW); my = view.toScreenCoordY(yRW); endPoint.x = xRW; endPoint.y = yRW; view.getEuclidianController().setLineEndPoint(endPoint); } else view.getEuclidianController().setLineEndPoint(null); line.setLine(coordsA[0], coordsA[1], mx, my); } }
public Point2D.Double projectInverse(double xyx, double xyy, Point2D.Double out) { double c; out.y = MapMath.asin(xyy / C_y); out.x = xyx / (C_x * ((c = Math.cos(out.y)) - 0.5)); out.y = MapMath.asin((out.y + Math.sin(out.y) * (c - 1.)) / C_p); return out; }
/** * Returns a coordinate location starting from (x,y) and proceeding the given travel distance at * the given heading. * * @param x starting x-coordinate * @param y starting y-coordinate * @param travelDistance distance to travel from starting coordinate * @param headingRoboDegrees heading to travel in (in Robocode degrees) * @return location after traveling the given distance at the given heading */ public static Point2D.Double getLocation( double x, double y, double travelDistance, double headingRoboDegrees) { double pheta = Math.toRadians(convertDegrees(headingRoboDegrees)); Point2D.Double location = new Point2D.Double(); location.x = x + travelDistance * Math.cos(pheta); location.y = y + travelDistance * Math.sin(pheta); return location; }
private void calculatePpvVsScore() { if (needToRecalculate && this.data != null && this.data.hasPositives()) { int window = 100; CovariationTriplet[] triplets = new CovariationTriplet[this.data.getNumberOfElements()]; int tripletCounter = 0; for (int i = 1; i <= this.data.getMatrixSize(); i++) { for (int j = i + 1; j <= this.data.getMatrixSize(); j++) { triplets[tripletCounter] = new CovariationTriplet(i, j, this.data.getMatrix().getValue(i, j)); tripletCounter++; } } this.data.getMatrix().getMin(); Arrays.sort(triplets, CovariationTriplet.getComparator(true)); List<Point2D.Double> ppvVsScore = new ArrayList<>(); Point2D.Double firstPoint = new Point2D.Double(0, 0); ppvVsScore.add(firstPoint); Set<Pair<Integer, Integer>> positives = this.data.getPositives(); for (int i = 0; i < window; i++) { firstPoint.x += triplets[0].getValue(); Pair<Integer, Integer> pair = new Pair<>(triplets[i].getNominalX(), triplets[i].getNominalY()); firstPoint.y += positives.contains(pair) ? 1 : 0; } Point2D.Double currentPoint = new Point2D.Double(firstPoint.x, firstPoint.y); for (int i = window; i < triplets.length; i++) { Pair<Integer, Integer> pairBegin = new Pair<>(triplets[i - window].getNominalX(), triplets[i - window].getNominalY()); Pair<Integer, Integer> pairNew = new Pair<>(triplets[i].getNominalX(), triplets[i].getNominalY()); currentPoint = new Point2D.Double( currentPoint.x - triplets[i - window].getValue() + triplets[i].getValue(), currentPoint.y - (positives.contains(pairBegin) ? 1 : 0) + (positives.contains(pairNew) ? 1 : 0)); ppvVsScore.add(currentPoint); } this.ppvVsScore = ppvVsScore; } }
// assumes that shapes are specified // in counter clockwise order public static ArrayList<Point2D.Double> calcOutwardNormals(ArrayList<Point2D.Double> shape) { int numVertices = shape.size(); ArrayList<Point2D.Double> normals = new ArrayList<Point2D.Double>(numVertices); Point2D.Double v1 = new Point2D.Double(); Point2D.Double v2 = new Point2D.Double(); Point2D.Double p0 = shape.get(0); Point2D.Double p1 = shape.get(1); for (int i = 0; i < numVertices; ++i) { Point2D.Double p2 = shape.get((i + 2) % numVertices); v1.x = p0.x - p1.x; v1.y = p0.y - p1.y; v2.x = p2.x - p1.x; v2.y = p2.y - p1.y; double angle = Utility.signedAngleBetweenVectorsInStandardPosition(v1, v2); // dx = x2-x1 and dy=y2-y1, // then the normals are (-dy, dx) and (dy, -dx) Point2D.Double n = new Point2D.Double(v1.y, -v1.x); double dot = n.x * v2.x + n.y * v2.y; if (angle < Math.PI) { if (dot < 0) { n.y = -n.y; n.x = -n.x; } } else { if (dot > 0) { n.y = -n.y; n.x = -n.x; } } double invLen = 1.0 / Math.sqrt(n.x * n.x + n.y * n.y); n.x *= invLen; n.y *= invLen; normals.add(n); p0 = p1; p1 = p2; } return normals; }
/** * @return vector pointing from one vector to another, scaled to specified length; returns zero * vector if from/to points are equal */ public static Point2D.Double scaledUnitVector( double length, Point2D.Double from, Point2D.Double to) { Point2D.Double dir = new Point2D.Double(to.x - from.x, to.y - from.y); double magn = dir.distance(0, 0); if (magn == 0) return new Point2D.Double(); dir.x *= length / magn; dir.y *= length / magn; return dir; }
/** Overridden for slight efficiency gain. */ @Override public boolean project(double rx, double ry, double rz, Point2D.Double pos) { if (rx >= 0) { pos.x = ry; pos.y = rz; return true; } else { return false; } }
/** * @param screenPoint {@link Point} of a screen position * @return original data Point corresponding to the specified screen position */ private Point2D getDataPoint(Point screenPoint) { Point2D.Double retPoint = new Point2D.Double(); retPoint.x = (((screenPoint.x - PAD) * (xAxis.getMax() - xAxis.getMin())) / (getWidth() - (2 * PAD))) + xAxis.getMin(); retPoint.y = (-1 * ((((screenPoint.y - getHeight()) + PAD) * (yAxis.getMax() - yAxis.getMin())) / (getHeight() - (2 * PAD)))) + yAxis.getMin(); return retPoint; }
/** * Calculates the default label position that is the center of the given points. * * @return */ @Override public Point2D.Double getDefaultPosition() { Point2D.Double result = new Point2D.Double(); if (this.fEdge == null) { // n-Ary association Rectangle2D diamondNodeBounds = this.fSource.getBounds(); result.x = diamondNodeBounds.getCenterX() - (getBounds().getWidth() / 2); result.y = diamondNodeBounds.getY() - 30; } else if (this.fEdge.isReflexive()) { BinaryAssociationOrLinkEdge binaryEdge = (BinaryAssociationOrLinkEdge) this.fEdge; if (binaryEdge.getReflexivePosition().isLocatedNorth()) { result.y = binaryEdge.getWayPointMostTo(Direction.NORTH).getCenter().getY() - getBounds().getHeight(); } else { result.y = binaryEdge.getWayPointMostTo(Direction.SOUTH).getCenter().getY() + 4; } double westX = binaryEdge.getWayPointMostTo(Direction.WEST).getCenter().getX(); double eastX = binaryEdge.getWayPointMostTo(Direction.EAST).getCenter().getX(); result.x = westX + (eastX - westX) / 2 - getBounds().getWidth() / 2; } else { Point2D sourceCenter = sourceWayPoint.getCenter(); Point2D targetCenter = targetWayPoint.getCenter(); result.x = sourceCenter.getX() + (targetCenter.getX() - sourceCenter.getX()) / 2 - getBounds().getWidth() / 2; result.y = sourceCenter.getY() + (targetCenter.getY() - sourceCenter.getY()) / 2 - getBounds().getHeight(); } return result; }
protected double subLength(double leftLegLen, double rightLegLen, double maxErr) { count++; double cldx, cldy, cdx, cdy; cldx = p3.x - p2.x; cldy = p3.y - p2.y; double crossLegLen = Math.sqrt(cldx * cldx + cldy * cldy); cdx = p4.x - p1.x; cdy = p4.y - p1.y; double cordLen = Math.sqrt(cdx * cdx + cdy * cdy); double hullLen = leftLegLen + rightLegLen + crossLegLen; if (hullLen < maxErr) return (hullLen + cordLen) / 2; double err = (hullLen - cordLen); if (err < maxErr) return (hullLen + cordLen) / 2; Cubic c = new Cubic(); double npX = (p1.x + 3 * (p2.x + p3.x) + p4.x) * 0.125; double npY = (p1.y + 3 * (p2.y + p3.y) + p4.y) * 0.125; double npdx = (cldx + cdx) * .125; double npdy = (cldy + cdy) * .125; c.p1.x = p1.x; c.p1.y = p1.y; c.p2.x = (p2.x + p1.x) * .5; c.p2.y = (p2.y + p1.y) * .5; c.p3.x = npX - npdx; c.p3.y = npY - npdy; c.p4.x = npX; c.p4.y = npY; double midLen = Math.sqrt(npdx * npdx + npdy * npdy); double len = c.subLength(leftLegLen / 2, midLen, maxErr / 2); c.p1.x = npX; c.p1.y = npY; c.p2.x = npX + npdx; c.p2.y = npY + npdy; c.p3.x = (p4.x + p3.x) * .5; c.p3.y = (p4.y + p3.y) * .5; c.p4.x = p4.x; c.p4.y = p4.y; len += c.subLength(midLen, rightLegLen / 2, maxErr / 2); return len; }
/** * Reads, but does not write, start and target points. Writes, but does not read, current point. */ public void interpolate2D( Interpolation mode, double pct, Point2D.Double start, Point2D.Double current, Point2D.Double target) { if (mode == Interpolation.LINEAR) { current.x = Crossfade.linear(pct, start.x, target.x); current.y = Crossfade.linear(pct, start.y, target.y); } else if (mode == Interpolation.SINUSOIDAL) { current.x = Crossfade.sinusoidal(pct, start.x, target.x); current.y = Crossfade.sinusoidal(pct, start.y, target.y); } else if (mode == Interpolation.ROOT) { current.x = Crossfade.exponential(pct, rootModePower, start.x, target.x); current.y = Crossfade.exponential(pct, rootModePower, start.y, target.y); } else if (mode == Interpolation.POWER) { current.x = Crossfade.exponential(pct, powerModePower, start.x, target.x); current.y = Crossfade.exponential(pct, powerModePower, start.y, target.y); } else { throw new IllegalArgumentException("Unsupported interpolation " + mode); } }
public void mouseDragged(MouseEvent me) { if (selectedPoint != null) { try { Point p = me.getPoint(); this.getMmToPxTransform().createInverse().transform(p, p); selectedPoint.x = p.x; selectedPoint.y = p.y; } catch (NoninvertibleTransformException ex) { Logger.getLogger(CalibrationPanel.class.getName()).log(Level.SEVERE, null, ex); } this.repaint(); } }
/** * Compute the position of a sprite if attached to a node. * * @param sprite The sprite. * @param pos Where to stored the computed position, if null, the position is created. * @param units The units the computed position must be given into. * @return The same instance as pos, or a new one if pos was null. */ protected Point2D.Double getSpritePositionNode( GraphicSprite sprite, Point2D.Double pos, Units units) { if (pos == null) pos = new Point2D.Double(); GraphicNode node = sprite.getNodeAttachment(); pos.x = node.x + sprite.getX(); pos.y = node.y + sprite.getY(); if (units == Units.PX) Tx.transform(pos, pos); return pos; }
private double findRadiusForWidth(int w, double rLower, double rUpper) { double rGuess = (rUpper + rLower) / 2; if (rGuess == rLower || rGuess == rUpper) return rGuess; projection.setEllipsoid(new Ellipsoid("", rGuess, rGuess, 0.0D, "")); projection.initialize(); int minx = Integer.MAX_VALUE; int maxx = -minx; int miny = minx; int maxy = -minx; Point2D.Double tmpin = new Point2D.Double(); Point2D.Double tmpout = new Point2D.Double(); double dlon = projection.getMaxLongitude() - projection.getMinLongitude(); double dlat = projection.getMaxLatitude() - projection.getMinLatitude(); for (int lo = 0; lo <= 100; lo++) { for (int la = 0; la <= 100; la++) { tmpin.x = (lo - 50) * dlon / 100; tmpin.y = (la - 50) * dlat / 100; tmpin.x = (lo - 50) * dlon / 100; tmpin.y = (la - 50) * dlat / 100; projection.transformRadians(tmpin, tmpout); if (tmpout.x < minx) minx = (int) tmpout.x; if (tmpout.y < miny) miny = (int) tmpout.y; if (tmpout.x > maxx) maxx = (int) tmpout.x; if (tmpout.y > maxy) maxy = (int) tmpout.y; } } int foundWidth = maxx - minx + 1; if (w == foundWidth) return rGuess; else if (foundWidth > w) return findRadiusForWidth(w, rLower, rGuess); else return findRadiusForWidth(w, rGuess, rUpper); }
public void vec2FieldMagnitude(Field field, AffineTransform ftoi) { AffineTransform itof = null; try { itof = ftoi.createInverse(); } catch (NoninvertibleTransformException niv) { TDebug.println(0, "NoninvertibleTransformException: " + niv); } Vector3d v = new Vector3d(); Point2D.Double p = new Point2D.Double(); for (int j = 0, k = 0; j < height; ++j) for (int i = 0; i < width; ++i, ++k) { p.x = i; p.y = j; itof.transform(p, p); v = field.get(p.x, p.y, 0.0); f[k] = (float) Math.sqrt(v.x * v.x + v.y * v.y); } }
public Point2D.Double project(double lplam, double lpphi, Point2D.Double out) { double th1, c; int i; c = C * Math.sin(lpphi); for (i = NITER; i > 0; --i) { out.y -= th1 = (Math.sin(.5 * lpphi) + Math.sin(lpphi) - c) / (.5 * Math.cos(.5 * lpphi) + Math.cos(lpphi)); if (Math.abs(th1) < EPS) { break; } } out.x = FXC * lplam * (1.0 + 2. * Math.cos(lpphi) / Math.cos(0.5 * lpphi)); out.y = FYC * Math.sin(0.5 * lpphi); return out; }