Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Plot trajectories on a sphere?

Subject: Plot trajectories on a sphere?

From: Anil Seth

Date: 09 Jan, 2008 14:26:16

Message: 1 of 6

I would be VERY grateful for advice. Basically I want to
plot an x,y trajectory on the surface of a sphere. The data
I have are in the following form:

x: a vector (N) in [-200,200]
y: a vector (N) in [-200,200]

NB these vectors are toroidal in the sense that -201 maps to
199.

What I want:

plot these trajectories on a sphere of fixed radius (ie non
deformed).

Simple question: If all this is too much, just tell me how
to plot a line on the surface of a sphere!

Thanks!

Thanks

Subject: Re: Plot trajectories on a sphere?

From: Roger Stafford

Date: 09 Jan, 2008 15:16:03

Message: 2 of 6

"Anil Seth" <a.k.seth.nospamplease@sussex.ac.uk> wrote in message
<fm2li8$ntr$1@fred.mathworks.com>...
> I would be VERY grateful for advice. Basically I want to
> plot an x,y trajectory on the surface of a sphere. The data
> I have are in the following form:
>
> x: a vector (N) in [-200,200]
> y: a vector (N) in [-200,200]
>
> NB these vectors are toroidal in the sense that -201 maps to
> 199.
>
> What I want:
>
> plot these trajectories on a sphere of fixed radius (ie non
> deformed).
>
> Simple question: If all this is too much, just tell me how
> to plot a line on the surface of a sphere!
>
> Thanks!
>
> Thanks
--------
  I'm not sure what it is that puzzles you, Anil. If you anticipate that x or y
will have numbers outside the range you describe, you would first perform:

 x = mod(x+200,400)-200;
 y = mod(y+200,400)-200;

to do your "toroidal" thing.

  You can find the corresponding z vector from:

 z = z0 + sqrt(r^2-(x-x0).^2-(y-y0).^2);

for the upper surface (subtract the square root for the lower surface) of the
sphere with radius r and center at (x0,y0,z0). (Any z's that are imaginary
would be points that don't project onto the sphere.)

 If your successive points in the (x,y,z) vectors are far apart and you wish to
connect them with a great circle arc on the sphere rather than a straight line,
that can be done in terms of cross products of three-dimensional vectors.
Let me know if this latter is your actual problem and I can give the necessary
formula.

Roger Stafford

Subject: Re: Plot trajectories on a sphere?

From: David

Date: 09 Jan, 2008 15:42:02

Message: 3 of 6

"Anil Seth" <a.k.seth.nospamplease@sussex.ac.uk> wrote in
message <fm2li8$ntr$1@fred.mathworks.com>...
> I would be VERY grateful for advice. Basically I want to
> plot an x,y trajectory on the surface of a sphere. The
data
> I have are in the following form:
>
> x: a vector (N) in [-200,200]
> y: a vector (N) in [-200,200]
>
> NB these vectors are toroidal in the sense that -201
maps to
> 199.
>
> What I want:
>
> plot these trajectories on a sphere of fixed radius (ie
non
> deformed).
>
> Simple question: If all this is too much, just tell me
how
> to plot a line on the surface of a sphere!
>
> Thanks!
>
> Thanks

since i can't figure out what kind of data you really have
from what you wrote above, here is something generic.
this plots a sphere with the earth topo on it then draws a
3 line trajectory with vectors at each point projected
onto the surface.

scale=100;

%plot a sphere with radius scale
load('topo.mat','topo','topomap1');
[X,Y,Z]=sphere(24);

X=X*scale;
Y=Y*scale;
Z=Z*scale;

h = surface(X,Y,Z,'FaceColor','texture','CData',topo);
rotate(h,[0 0 1],180)
colormap(topomap1)
hold on

%made up numbers for trajectory and vectors at 4 points
xt=[0;5;6;10];
vxt=[0;0;1;1];
yt=[5;10;15;16];
vyt=[1;1;0;0];
zt=[100;95;90;85];
vzt=[.1;.1;.1;.1];

%convert to spherical coords
[T,P,R]=cart2sph(xt,yt,zt);
%project onto surface of sphere by making radius constant
R(:)=scale;
%convert back to cartesian for plotting
[xt,yt,zt]=sph2cart(T,P,R);

%plot
plot3(xt,yt,zt,'r')
quiver3(xt,yt,zt,vxt,vyt,vzt,1,'y-');
  
hold off

Subject: Re: Plot trajectories on a sphere?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 09 Jan, 2008 18:12:17

Message: 4 of 6

In article <fm2ofj$evq$1@fred.mathworks.com>,
Roger Stafford <ellieandrogerxyzzy@mindspring.com.invalid> wrote:
>If you anticipate that x or y
>will have numbers outside the range you describe, you would first perform:

> x = mod(x+200,400)-200;
> y = mod(y+200,400)-200;

>to do your "toroidal" thing.

If you have a vector that crosses the boundary, then would not
taking the mod like that would result in a large jump back rather
than in smooth crossing of the boundary?
--
   "No one has the right to destroy another person's belief by
   demanding empirical evidence." -- Ann Landers

Subject: Re: Plot trajectories on a sphere?

From: Roger Stafford

Date: 09 Jan, 2008 18:27:01

Message: 5 of 6

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message <fm32q1
$rak$1@canopus.cc.umanitoba.ca>...
> In article <fm2ofj$evq$1@fred.mathworks.com>,
> Roger Stafford <ellieandrogerxyzzy@mindspring.com.invalid> wrote:
> >If you anticipate that x or y
> >will have numbers outside the range you describe, you would first
perform:
>
> > x = mod(x+200,400)-200;
> > y = mod(y+200,400)-200;
>
> >to do your "toroidal" thing.
>
> If you have a vector that crosses the boundary, then would not
> taking the mod like that would result in a large jump back rather
> than in smooth crossing of the boundary?
-------
Yes, that worried me too, Walter. It is to be hoped that in any given
"trajectory" all the points would be shifted by mod in the same way. I think
we need a lot more clarification from Anil.

Roger Stafford

Subject: Re: Plot trajectories on a sphere?

From: Charles Cuell

Date: 09 Jan, 2008 18:58:02

Message: 6 of 6

"Anil Seth" <a.k.seth.nospamplease@sussex.ac.uk> wrote in
message <fm2li8$ntr$1@fred.mathworks.com>...
> I would be VERY grateful for advice. Basically I want to
> plot an x,y trajectory on the surface of a sphere. The
data
> I have are in the following form:
>
> x: a vector (N) in [-200,200]
> y: a vector (N) in [-200,200]
>
> NB these vectors are toroidal in the sense that -201 maps
to
> 199.
>
> What I want:
>
> plot these trajectories on a sphere of fixed radius (ie
non
> deformed).
>
> Simple question: If all this is too much, just tell me
how
> to plot a line on the surface of a sphere!
>
> Thanks!
>
> Thanks

If your data vectors, x and y, are already "toroidal", then
I presume that means they are representing angles? If that
is the case then the x and y are representing points on the
surface of a torus and you need a transformation that takes
points on a torus to points on a sphere. If so, the trouble
is that a sphere is not a torus and there is no nice
transformation.
 
Charles

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
cart2sph David 09 Jan, 2008 10:45:08
sphere David 09 Jan, 2008 10:45:08
plot3 David 09 Jan, 2008 10:45:08
sph2cart David 09 Jan, 2008 10:45:08
quiver3 David 09 Jan, 2008 10:45:08
spherical graphics Anil Seth 09 Jan, 2008 09:30:14
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics