-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from adtewa/feature/5_given_two_coordinates_de…
…termine_visibility Feature/5 given two coordinates determine visibility
- Loading branch information
Showing
7 changed files
with
232 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/hu/awm/srtm/tools/cansee/CanSeeCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package hu.awm.srtm.tools.cansee; | ||
|
||
import hu.awm.srtm.data.hgt.Tile; | ||
import hu.awm.srtm.data.hgt.TileMap; | ||
import hu.awm.srtm.map.contour.ContourCalculator; | ||
|
||
public class CanSeeCalculator { | ||
|
||
private Vector3D from; | ||
private Vector3D to; | ||
private TileMap tileMap; | ||
|
||
public CanSeeCalculator() { | ||
|
||
} | ||
|
||
public void setCoordinates(Double fromLat, Double fromLon, Double fromHeight, Double toLat, Double toLon, Double toHeight) { | ||
this.from = new Vector3D(fromLat, fromLon, fromHeight); | ||
this.to = new Vector3D(toLat, toLon, toHeight); | ||
} | ||
|
||
public void setTileMap(TileMap tileMap) { | ||
this.tileMap = tileMap; | ||
} | ||
|
||
public Sight calculateSight() { | ||
Vector3D loseSightCoordinate = null; | ||
Vector3D directionVector = to.subtract(from); | ||
double stepCount = Math.max(Math.abs(to.getLat() - from.getLat()) * Tile.RESOLUTION, | ||
Math.abs(to.getLon() - from.getLon()) * Tile.RESOLUTION) * 2; | ||
Vector3D stepVector = directionVector.getInstanceResizedToLength(directionVector.length() / stepCount); | ||
|
||
for (Vector3D i = from.newInstance(); i.lengthTo(to) > stepVector.length(); i = i.add(stepVector)) { | ||
if (!isPointVisible(i)) { | ||
loseSightCoordinate = i.newInstance(); | ||
break; | ||
} | ||
} | ||
if (loseSightCoordinate == null) { | ||
if (!isPointVisible(to)) { | ||
loseSightCoordinate = to.newInstance(); | ||
} | ||
} | ||
return new Sight(from, to, loseSightCoordinate); | ||
} | ||
|
||
public boolean calculateBoolean() { | ||
Sight sight = calculateSight(); | ||
return !sight.hasBlocker(); | ||
} | ||
|
||
private boolean isPointVisible(Vector3D pointToCheck) { | ||
int tileLat = pointToCheck.getLat().intValue(); | ||
int tileLon = pointToCheck.getLon().intValue(); | ||
Tile tile = tileMap.getByLatLon(tileLat, tileLon); | ||
double height = tile.elevationByExactCoordinates(pointToCheck.getLat(), pointToCheck.getLon()); | ||
return height <= pointToCheck.getHeight(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package hu.awm.srtm.tools.cansee; | ||
|
||
public class Sight { | ||
private Vector3D startCoordinate; | ||
private Vector3D endCoordinate; | ||
private Vector3D looseSightCoordinate; | ||
|
||
public Sight() { | ||
} | ||
|
||
public Sight(Vector3D startCoordinate, Vector3D endCoordinate, Vector3D looseSightCoordinate) { | ||
this.startCoordinate = startCoordinate; | ||
this.endCoordinate = endCoordinate; | ||
this.looseSightCoordinate = looseSightCoordinate; | ||
} | ||
|
||
public Vector3D getStartCoordinate() { | ||
return startCoordinate; | ||
} | ||
|
||
public void setStartCoordinate(Vector3D startCoordinate) { | ||
this.startCoordinate = startCoordinate; | ||
} | ||
|
||
public Vector3D getEndCoordinate() { | ||
return endCoordinate; | ||
} | ||
|
||
public void setEndCoordinate(Vector3D endCoordinate) { | ||
this.endCoordinate = endCoordinate; | ||
} | ||
|
||
public Vector3D getLooseSightCoordinate() { | ||
return looseSightCoordinate; | ||
} | ||
|
||
public void setLooseSightCoordinate(Vector3D looseSightCoordinate) { | ||
this.looseSightCoordinate = looseSightCoordinate; | ||
} | ||
|
||
public boolean hasBlocker() { | ||
return this.looseSightCoordinate != null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package hu.awm.srtm.tools.cansee; | ||
|
||
public class Vector3D { | ||
private Double lat; | ||
private Double lon; | ||
private Double height; | ||
|
||
public Vector3D(Double lat, Double lon, Double height) { | ||
this.lat = lat; | ||
this.lon = lon; | ||
this.height = height; | ||
} | ||
|
||
public Vector3D newInstance() { | ||
return new Vector3D(this.lat, this.lon, this.height); | ||
} | ||
|
||
public Double getLat() { | ||
return lat; | ||
} | ||
|
||
public Double getLon() { | ||
return lon; | ||
} | ||
|
||
public Double getHeight() { | ||
return height; | ||
} | ||
|
||
public Vector3D getInstanceResizedToLength(Double newLength) { | ||
Double ratio = newLength / length(); | ||
return new Vector3D(lat * ratio, lon * ratio, height * ratio); | ||
} | ||
|
||
public Double length() { | ||
return Math.sqrt(Math.pow(lat, 2.0) | ||
+ Math.pow(lon, 2.0) | ||
+ Math.pow(height, 2.0)); | ||
} | ||
|
||
public static Vector3D subtract(Vector3D from, Vector3D what) { | ||
return from.subtract(what); | ||
} | ||
|
||
public Vector3D subtract(Vector3D what) { | ||
return new Vector3D(this.lat - what.getLat(), | ||
this.lon - what.getLon(), | ||
this.height - what.getHeight()); | ||
} | ||
|
||
public static Vector3D add(Vector3D to, Vector3D what) { | ||
return to.add(what); | ||
} | ||
|
||
public Vector3D add(Vector3D what) { | ||
return new Vector3D(this.lat + what.getLat(), | ||
this.lon + what.getLon(), | ||
this.height + what.getHeight()); | ||
} | ||
|
||
public double lengthTo(Vector3D what) { | ||
return what.subtract(this).length(); | ||
} | ||
} |