<p>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.</p>

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

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

CC BY-SA 3.0
2016-01-21T12:07:46.430Z
2016-01-21T12:07:46.430Z
Mikkel Gjoel
<p>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.</p>

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

<p><strong>EDIT</strong></p>

<p>It looks like most of the code in use was copied from this example: <a href="http://worldwind31.arc.nasa.gov/svn/trunk/WorldWind/src/gov/nasa/worldwind/util/BasicDragger.java" rel="nofollow">http://worldwind31.arc.nasa.gov/svn/trunk/WorldWind/src/gov/nasa/worldwind/util/BasicDragger.java</a></p>

<p>The line of code in the example that confuses me the most is</p>

<pre><code>double y = event.getMouseEvent().getComponent().getSize().height -
                                       this.dragRefObjectPoint.y + dy - 1;
</code></pre>

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

<p>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).</p>

CC BY-SA 3.0
2016-01-20T18:53:01.593Z
How are you representing the rectangle, and how are you moving it? Can you share the relevant sections of your code?
Nathan Reed
CC BY-SA 3.0
2016-01-20T20:20:24.237Z
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.
trichoplax is on Codidact now
CC BY-SA 3.0
2016-01-20T22:27:34.393Z
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.
Erik
CC BY-SA 3.0
2016-01-21T05:25:11.487Z
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.
joojaa
CC BY-SA 3.0
2016-01-21T15:26:45.447Z
@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.
Erik
<rendering><geometry>
Slide a rectangle along a sphere
Erik
# Slide a rectangle along a sphere

(Asked by: username_0 on 2016-01-20)

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?

**EDIT**

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).

**Tags:** rendering, geometry

> **Comments:**
> **username_1**: How are you representing the rectangle, and how are you moving it? Can you share the relevant sections of your code?  
> **username_2**: 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.  
> **username_0**: 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.  
> **username_3**: 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.  
> **username_0**: @username_3: 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.  

---

## 1 answers

### Answer by username_4 on 2016-01-21. Score: 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.


---

