I'm using NASA WorldWind to place a rectangle on the Earth ('sphere'). When I drag the rectangle on the sphere, the rectangle changes shape and size but the dimensions should be preserved.

What is needed to preserve the rectangle's original dimensions when it is dragged along the Earth/sphere?


It looks like most of the code in use was copied from this example: http://worldwind31.arc.nasa.gov/svn/trunk/WorldWind/src/gov/nasa/worldwind/util/BasicDragger.java

The line of code in the example that confuses me the most is

double y = event.getMouseEvent().getComponent().getSize().height -
                                       this.dragRefObjectPoint.y + dy - 1;

The resulting behavior is the 'rectangle' that is mapped to the globe changes shape and size.

I also want to point out my experience with computer graphics and NASA worldwind are limited. I'm especially rusty on linear algebra and very weak with geomtery. I'd appreciate suggestions on resources (outside of the obvious NASA WorldWind reference).

  • 2
    $\begingroup$ How are you representing the rectangle, and how are you moving it? Can you share the relevant sections of your code? $\endgroup$ Jan 20, 2016 at 18:53
  • 1
    $\begingroup$ We will need more detail on what you are trying to achieve, and what you have tried so far so we don't duplicate effort. $\endgroup$ Jan 20, 2016 at 20:20
  • $\begingroup$ I'm new to this code base so I'm still figuring things out. I'll update the question with some more information when I get time. $\endgroup$
    – Erik
    Jan 20, 2016 at 22:27
  • 1
    $\begingroup$ There is no such thing as a straight line on a sphere. Thus no rectangle. But most likely also your coordinate system is cylindrical causing the cordinates not to be uniform. $\endgroup$
    – joojaa
    Jan 21, 2016 at 5:25
  • $\begingroup$ @joojaa: A rectangle is mapped on to a sphere. The coordinates on the globe are LatLon but from what I can tell, the X and Y used aren't related. $\endgroup$
    – Erik
    Jan 21, 2016 at 15:26

1 Answer 1


If I understand you correctly, the problem could be defined as the (edge) intersection of a cube with a sphere. In that case, you could shade the edges by calculating the distance to the edges of the cube.

//note: from http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
float udBox( vec3 p, vec3 b )
  return length(max(abs(p)-b,0.0));

Aligning the cube poses another "interesting" issue - you probably want to use the sphere-normal and screen-up to generate a basis.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.