-
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.
- Modified Tile to have a function to get height by double lat/lon. - Renamed Xyz to Vector3D and added some useful functions to it. - Implemented the main calculation for CanSeeCalculator. - Added examples to readme.
- Loading branch information
1 parent
b7ec5f0
commit 27246e8
Showing
7 changed files
with
139 additions
and
42 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
38 changes: 32 additions & 6 deletions
38
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 |
---|---|---|
@@ -1,33 +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 Xyz from; | ||
private Xyz to; | ||
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 Xyz(fromLat, fromLon, fromHeight); | ||
this.to = new Xyz(toLat, toLon, 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() { | ||
// TODO: Replace this with the correct math. | ||
return new Sight(null, null, null); | ||
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
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(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.