List of usage examples for java.awt.geom Line2D intersectsLine
public boolean intersectsLine(Line2D l)
From source file:GeometryUtilities.java
public static Vector<Point2D> getCrossings(Line2D line0, Line2D line1) { Vector<Point2D> ret = new Vector<Point2D>(); if (line0.intersectsLine(line1)) { Point2D.Double intersection = new Point2D.Double(0.0, 0.0); double xDiff0 = line0.getX2() - line0.getX1(); double xDiff1 = line1.getX2() - line1.getX1(); double yDiff0 = line0.getY2() - line0.getY1(); double yDiff1 = line1.getY2() - line1.getY1(); double xDiff2 = line0.getX1() - line1.getX1(); double yDiff2 = line0.getY1() - line1.getY1(); double div = yDiff1 * xDiff0 - xDiff1 * yDiff0; double u = (xDiff1 * yDiff2 - yDiff1 * xDiff2) / div; intersection.x = line0.getX1() + u * xDiff0; intersection.y = line0.getY1() + u * yDiff0; ret.add(intersection);/*from w w w . j a v a 2s.c o m*/ } return ret; }
From source file:com.wasteofplastic.beaconz.Register.java
/** * Creates a triangular field covering the world between three beacons * @param point2d/*w w w .j a va 2 s. c o m*/ * @param point2d2 * @param point2d3 * @return */ public Boolean addTriangle(Point2D point2d, Point2D point2d2, Point2D point2d3, Team owner) throws IllegalArgumentException { //getLogger().info("DEBUG: Adding triangle at " + point2d + " " + point2d2 + " " + point2d3); // Check that locations are known beacons if (beaconRegister.containsKey(point2d) && beaconRegister.containsKey(point2d2) && beaconRegister.containsKey(point2d3)) { //getLogger().info("DEBUG: All three beacons are in the register"); // Check the beacons are all owned by the same faction if (beaconRegister.get(point2d).getOwnership().equals(owner) && beaconRegister.get(point2d2).getOwnership().equals(owner) && beaconRegister.get(point2d3).getOwnership().equals(owner)) { //getLogger().info("DEBUG: All beacons are owned by same faction"); TriangleField triangle = new TriangleField(point2d, point2d2, point2d3, owner); // Check to see if this control field would overlap enemy-held beacons // Allow this for now /* for (Entry<Point2D,BeaconObj> beacon : getRegister().getBeaconRegister().entrySet()) { if (beacon.getValue().getOwnership() != null && !beacon.getValue().getOwnership().equals(owner)) { // Check enemy beacons if (cf.contains(beacon.getKey())) { getLogger().info("DEBUG: Enemy beacon found inside potential control field, not making control field"); return false; } } }*/ // Check if any triangle or lines intersect for (TriangleField triangleField : triangleFields) { // Check if triangle is inside any of the known triangles if (!triangle.getOwner().equals(triangleField.getOwner()) && (triangleField.contains(triangle) || triangle.contains(triangleField))) { //getLogger().info("DEBUG: Enemy triangle found inside triangle!"); return false; } } for (Entry<Team, Set<Line2D>> linkSet : links.entrySet()) { if (!linkSet.getKey().equals(owner)) { for (Line2D link : linkSet.getValue()) { for (Line2D side : triangle.getSides()) { if (side.intersectsLine(link)) { //getLogger().info("DEBUG: Enemy beacon link found inside triangle!"); return false; } } } } } if (triangleFields.add(triangle)) { //getLogger().info("DEBUG: Added control field!"); // New control field, refresh score getScorecard().refreshScores(owner, "area"); getScorecard().refreshScores(owner, "triangles"); //getLogger().info("DEBUG: New score is " + triangle.getArea()); return true; } else { // getLogger().info("DEBUG: Control field already exists"); } } else { //getLogger().info("DEBUG: beacons are not owned by the same faction"); throw new IllegalArgumentException("beacons are not owned by the same team"); } } else { //getLogger().info("DEBUG: Location argument is not a beacon"); throw new IllegalArgumentException("Location argument is not a beacon"); } return false; }
From source file:com.wasteofplastic.beaconz.BeaconListeners.java
/** * Tries to link two beacons//from w w w . j a va2s . com * @param player * @param team * @param beacon * @param otherBeacon * @return true if link is made successfully */ private boolean linkBeacons(Player player, Team team, BeaconObj beacon, BeaconObj otherBeacon) { if (beacon.equals(otherBeacon)) { player.sendMessage(ChatColor.RED + "You cannot link a beacon to itself!"); return false; } if (beacon.getNumberOfLinks() == 8) { player.sendMessage(ChatColor.RED + "This beacon already has 8 outbound links!"); return false; } // Check if this link already exists if (beacon.getLinks().contains(otherBeacon)) { player.sendMessage(ChatColor.RED + "Link already exists!"); return false; } // Proposed link Line2D proposedLink = new Line2D.Double(beacon.getLocation(), otherBeacon.getLocation()); // Check if the link crosses opposition team's links //getLogger().info("DEBUG: Check if the link crosses opposition team's links"); for (Line2D line : getRegister().getEnemyLinks(team)) { //getLogger().info("DEBUG: checking line " + line.getP1() + " to " + line.getP2()); if (line.intersectsLine(proposedLink)) { player.sendMessage(ChatColor.RED + "Link cannot cross enemy link!"); return false; } } // Link the two beacons! LinkResult result = beacon.addOutboundLink(otherBeacon); if (result.isSuccess()) { player.sendMessage(ChatColor.GREEN + "Link created!"); player.sendMessage(ChatColor.GREEN + "This beacon now has " + beacon.getNumberOfLinks() + " links"); player.getWorld().playSound(player.getLocation(), Sound.FIREWORK_LARGE_BLAST, 1F, 1F); player.getWorld().spawnEntity(player.getLocation(), EntityType.EXPERIENCE_ORB); if (Settings.pairLinking) { // Tell the other player if it was done via a pairing if (standingOn.containsValue(otherBeacon)) { Player otherPlayer = getServer().getPlayer(standingOn.inverse().get(otherBeacon)); if (otherPlayer != null) { otherPlayer.sendMessage(ChatColor.GREEN + "Link created!"); otherPlayer.getWorld().playSound(otherPlayer.getLocation(), Sound.FIREWORK_LARGE_BLAST, 1F, 1F); otherPlayer.getWorld().spawnEntity(otherPlayer.getLocation(), EntityType.EXPERIENCE_ORB); } // Tell the team getMessages().tellTeam(player.getUniqueId(), player.getDisplayName() + ChatColor.GREEN + " and " + otherPlayer.getDisplayName() + ChatColor.GREEN + " created a link!"); // Taunt other teams getMessages().tellOtherTeams(team, ChatColor.GOLD + team.getDisplayName() + " team made a link!"); } } else { // Tell the team getMessages().tellTeam(player.getUniqueId(), player.getDisplayName() + ChatColor.GREEN + " created a link!"); } } else { player.sendMessage(ChatColor.RED + "Link could not be created!"); return false; } if (result.getFieldsMade() > 0) { if (result.getFieldsMade() == 1) { player.sendMessage( ChatColor.GREEN + "Triangle created! New score = " + getScorecard().getScore(team, "area")); getMessages().tellTeam(player.getUniqueId(), player.getDisplayName() + ChatColor.GREEN + " created a triangle! New team score = " + getScorecard().getScore(team, "area")); // Taunt other teams getMessages().tellOtherTeams(team, ChatColor.RED + team.getDisplayName() + " team made a tringle!"); } else { player.sendMessage(ChatColor.GREEN + String.valueOf(result.getFieldsMade()) + " triangles created! New score = " + getScorecard().getScore(team, "area")); getMessages().tellTeam(player.getUniqueId(), player.getDisplayName() + ChatColor.GREEN + " created " + String.valueOf(result.getFieldsMade()) + " triangles! New team score = " + getScorecard().getScore(team, "area")); // Taunt other teams getMessages().tellOtherTeams(team, ChatColor.RED + team.getDisplayName() + " team made " + String.valueOf(result.getFieldsMade()) + " triangles!"); } for (int i = 0; i < result.getFieldsMade(); i++) { player.getWorld().spawnEntity(player.getLocation(), EntityType.EXPERIENCE_ORB); } } if (result.getFieldsFailedToMake() > 0) { if (result.getFieldsFailedToMake() == 1) { player.sendMessage( ChatColor.RED + "One triangle could not be created because of overlapping enemy elements!"); } else { player.sendMessage(ChatColor.RED + String.valueOf(result.getFieldsFailedToMake()) + " triangle could not be created because of overlapping enemy elements!"); } } return true; }
From source file:com.china317.gmmp.gmmp_report_analysis.service.imp.DgmAnalysisImp.java
private boolean inEntryExit(VehicleLocate e, VehicleLocate old) { boolean re = false; double longtitude_before = old.getLon(); double latitude_before = old.getLat(); //LngLat in_before = new LngLat(longtitude_before, latitude_before); //LngLat des_before = CacheConvert.EncryptGPSUseCache(in_before); //double lon_before = des_before.getLng(); //double lat_before = des_before.getLat(); double ilongtitude_before = (longtitude_before * 1000000); double ilatitude_before = (latitude_before * 1000000); Point2D p_before = new Point2D.Double(ilongtitude_before, ilatitude_before); /*888888888888888888888888888888888888888888888888888888*/ double longtitude_after = e.getLon(); double latitude_after = e.getLat(); //LngLat in_after = new LngLat(longtitude_after, latitude_after); //LngLat des_after = CacheConvert.EncryptGPSUseCache(in_after); //double lon_after = des_after.getLng(); //double lat_after = des_after.getLat(); double ilongtitude_after = (longtitude_after * 1000000); double ilatitude_after = (latitude_after * 1000000); Point2D p_after = new Point2D.Double(ilongtitude_after, ilatitude_after); /*888888888888888888888888888888888888888888888888888888*/ ///*from www. ja va2 s . c om*/ Line2D line_normal = new Line2D.Double(p_before, p_after); for (int aa = 0; aa < linelist.size(); aa++) { Line2D l = linelist.get(aa); if (line_normal.intersectsLine(l)) { re = true; break; } } return re; }