private Point2D makeControlPoint(final double endX, final double endY, final Circle circle, final int numSegments, int direction) { final double controlPointDistance = (4.0 / 3.0) * Math.tan(Math.PI / (2 * numSegments)) * circle.getRadius(); final Point2D center = new Point2D(circle.getCenterX(), circle.getCenterY()); final Point2D end = new Point2D(endX, endY); Point2D perp = rotate(center, end, direction * Math.PI / 2.); Point2D diff = perp.subtract(end); diff = diff.normalize(); diff = scale(diff, controlPointDistance); return end.add(diff); }
private double[] circleFrom3Points(Point2D a, Point2D b, Point2D c) { double ax, ay, bx, by, cx, cy, x1, y11, dx1, dy1, x2, y2, dx2, dy2, ox, oy, dx, dy, radius; // Variables Used and to Declared ax = a.getX(); ay = a.getY(); //first Point X and Y bx = b.getX(); by = b.getY(); // Second Point X and Y cx = c.getX(); cy = c.getY(); // Third Point X and Y ////****************Following are Basic Procedure**********************/// x1 = (bx + ax) / 2; y11 = (by + ay) / 2; dy1 = bx - ax; dx1 = -(by - ay); x2 = (cx + bx) / 2; y2 = (cy + by) / 2; dy2 = cx - bx; dx2 = -(cy - by); ox = (y11 * dx1 * dx2 + x2 * dx1 * dy2 - x1 * dy1 * dx2 - y2 * dx1 * dx2) / (dx1 * dy2 - dy1 * dx2); oy = (ox - x1) * dy1 / dx1 + y11; dx = ox - ax; dy = oy - ay; radius = Math.sqrt(dx * dx + dy * dy); return new double[] {ox, oy, radius}; }
private Point2D getPointFromSL(int saturation, int lightness, double radius) { double dy = map(saturation, 0, 255, -radius, radius); double angle = 0.; double angle1 = angle + 2 * Math.PI / 3.; double angle2 = angle1 + 2 * Math.PI / 3.; double x1 = radius * Math.sin(angle1); double y1 = radius * Math.cos(angle1); double x2 = radius * Math.sin(angle2); double y2 = radius * Math.cos(angle2); double dx = 0; double[] circle = circleFrom3Points(new Point2D(x1, y1), new Point2D(dx, dy), new Point2D(x2, y2)); double xArc = circle[0]; double yArc = circle[1]; double arcR = circle[2]; double Arco1 = Math.atan2(x1 - xArc, y1 - yArc); double Arco2 = Math.atan2(x2 - xArc, y2 - yArc); double ArcoFinal = map(lightness, 0, 255, Arco2, Arco1); double finalX = xArc + arcR * Math.sin(ArcoFinal); double finalY = yArc + arcR * Math.cos(ArcoFinal); if (dy < y1) { ArcoFinal = map(lightness, 0, 255, Arco1, Arco2 + 2 * Math.PI); finalX = -xArc - arcR * Math.sin(ArcoFinal); finalY = yArc + arcR * Math.cos(ArcoFinal); } return new Point2D(finalX, finalY); }
/** * Compare two points. As the point coordinates are represented as double values, * they might be so close to be considered to be equal. * @param p1 first point * @param p2 second point * @return true if p1 is near p2. */ public boolean equals(Point2D p1, Point2D p2) { if (p1.equals(p2)) { return true; } else { return Math.abs(p1.getX() - p2.getX()) < DELTA && Math.abs(p1.getY() - p2.getY()) < DELTA; } } }
private void createGroundSensor(Entity e) { // 3 is a good ratio of entity width, since we don't want to occupy the full width // if we want to ban "ledge" jumps double sensorWidth = e.getWidth() / 3; double sensorHeight = 5; // assumes that origin of entity's main hit box is at 0,0 e.getComponent(PhysicsComponent.class).addGroundSensor(new HitBox("GROUND_SENSOR", new Point2D(e.getWidth() / 2, e.getHeight()).add(-sensorWidth / 2, -sensorHeight / 2), BoundingShape.box(sensorWidth, sensorHeight))); }
@VisibleForTesting ICity calculateCostructionCity() { double width = map.getDimension().getWidth(); List<ICity> chosableCities = map.getCities().stream() .filter(city -> city.getCoordinates().getX() < width * 0.5) .collect(toList()); return chosableCities.get(rnd.nextInt(chosableCities.size())); } }
/** * @return the screen y relative to the source */ public double getY() { return ((Node) getSource()).screenToLocal(this.screenX, this.screenY).getY(); }
private Shape polygon(Point2D[] points, Point2D boundsCenterLocal, Point2D bboxCenterLocal) { Vec2[] vertices = new Vec2[points.length]; for (int i = 0; i < vertices.length; i++) { vertices[i] = toVector(points[i].subtract(boundsCenterLocal)).subLocal(toVector(bboxCenterLocal)); } PolygonShape shape = new PolygonShape(); shape.set(vertices); return shape; }
/** * Updates {@link #mouseMoved} by checking whether the specified point is different from the * {@link #startingPoint}. * * @param point * the point which will be compared to the {@link #startingPoint} */ private void updateMouseMoved(Point2D point) { // if the mouse already moved, do nothing if (mouseMoved) { return; } // if the mouse did not move yet, check whether it did now boolean mouseMovedNow = !startingPoint.equals(point); mouseMoved = mouseMovedNow; }
/** * @param x position x of entity * @param y position y of entity * @return center point of this hit box in world coordinates */ public Point2D centerWorld(double x, double y) { return centerLocal().add(x, y); }
public CurveTransition(Point2D from, Point2D to) { this.from = from; double fromDx = from.getX() - centerX; double fromDy = from.getY() - centerY; fromTheta = Math.atan2(fromDy, fromDx); double toDx = to.getX() - centerX; double toDy = to.getY() - centerY; toTheta = Math.atan2(toDy, toDx); setInterpolator(Interpolator.EASE_BOTH); setDelay(Duration.millis(0)); setCycleDuration(Duration.millis(240)); }
/** * @return new emitter with smoke configuration */ public static ParticleEmitter newSmokeEmitter() { ParticleEmitter emitter = new ParticleEmitter(); emitter.setNumParticles(5); emitter.setEmissionRate(1); emitter.setSize(9, 10); emitter.setSpawnPointFunction(i -> Point2D.ZERO.add(random(-1, 1), 0)); emitter.setVelocityFunction(i -> new Point2D((random() * 0.1 * 60), 0)); emitter.setAccelerationFunction(() -> new Point2D(0, random() * -0.03)); emitter.setExpireFunction(i -> Duration.seconds(random(1, 3))); emitter.setColor(Color.rgb(230, 230, 230)); emitter.setScaleFunction(i -> new Point2D(-0.01, -0.05)); return emitter; }
private void addNewShipIconToCanvas(INavigableVessel vessel, List<Point2D> path) { ShipIcon shipIcon = new ShipIcon(vessel, viewState.getPlayer(), imageLoader); shipIcon.scaleProperty().bind(scale); shipIcon.updatePosition(); shipIcon.setTravelingEast(path.get(0).getX() < path.get(path.size() - 1).getX()); removeVesselFromView(vessel); shipCanvas.getChildren().add(shipIcon); }
private Shape chain(Point2D[] points, Point2D boundsCenterLocal, Point2D bboxCenterLocal) { Vec2[] vertices = new Vec2[points.length]; for (int i = 0; i < vertices.length; i++) { vertices[i] = toVector(points[i].subtract(boundsCenterLocal)).subLocal(toVector(bboxCenterLocal)); } ChainShape shape = new ChainShape(); shape.createLoop(vertices, vertices.length); return shape; }
/** * Check if the location matches any city. * @param location to check * @return true if the <code>location</code> is in any city. */ private boolean isInCity(Point2D location) { return map.getCityCoordinates().stream().anyMatch(coord -> coord.equals(location)); }