Fork me on GitHub

Line Of Sight


Video above from the Line Of Sight Example

This tutorial demonstrates the OmnidirectionalSightline class and how it can be used to display the line of sight visible portions of terrain given an origin.

OmnidirectionalSightline uses the GPU to determine the visible areas of terrain from a position. A Position and range is all that is needed for the OmnidirectionalSightline object to display the visible areas. Different colors are used to differentiate occluded and visible terrain.


OmnidirectionalSightlineFragment.java

The OmnidirectionalSightlineFragment class extends the BasicGlobeFragment and overrides the createWorldWindow method. An OmnidirectionalSightline object is created, customized with ShapeAttributes, and then added to a RenderableLayer on the WorldWindow.

Creating the OmnidirectionalSightline object:

// Specify the Sightline origin position
Position position = new Position(46.230, -122.190, 2500.0);
// Specify the range (meters)
double range = 10000.0
OmnidirectionalSightline sightline = new OmnidirectionalSightline(position, range);

The OmnidirectionalSightline object is now fully configured and ready to be added to the WorldWindow for display on the globe:

// Create a layer for the Sightline
RenderableLayer sightlineLayer = new RenderableLayer();
sightlineLayer.addRenderable(sightline);
wwd.getLayers().addLayer(sightlineLayer);

The color of the areas on terrain which are visible and occluded can be customized using ShapeAttributes:

// Create attributes for the visible terrain
ShapeAttributes visibleAttributes = new ShapeAttributes();
visibleAttributes.setInteriorColor(new Color(0f, 1f, 0f, 0.5f)); // Green for visible
// Create attributes for the occluded terrain
ShapeAttributes occludedAttributes = new ShapeAttributes();
occludedAttributes.setInteriorColor(new Color(0.1f, 0.1f, 0.1f, 0.5f)); // Gray for occluded
// Add the attributes
sightline.setAttributes(visibleAttributes);
sightline.setOccludeAttributes(occludedAttributes);

The OmnidirectionalSightlineFragment tutorial also adds a Placemark at the position specified for the OmnidirectionalSightline object. This isn’t necessary and is only added to provide a visual context of the sightline origin and results.


The code above should provide a view similar to this:



The OmnidirectionalSightline object uses the available terrain to test for line of sight. As you zoom in or get closer to the terrain, refinement occurs and the visible terrain may change. This tutorial is the simplest demonstration for Line of Sight. Please see this example for more functionality.



Server maintenance notice

Dear WorldWind Community,

The geospatial data services that feed WorldWind clients by default with data are undergoing maintenance. Outages between 2 to 4 hours per server may occur during the month of April 2023.

As always, if you have any inquiries or concerns, please contact us at:

arc-worldwind@mail.nasa.gov