ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 04 Dec 2010 19:08:31 +0100New Project Looking for Help: Plotting great circleshttps://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/Hi,
I'm working on a project and found that sage may be the best program to help. Information can be found at [vividdynamics.com](http://vividdynamics.com). I'm not a math student but study it as a hobby(mainly geometry) and have some art backround.
I'm looking for a way to generate a sphere with great circles plotted at cumulatively smaller intervals as they get closer to axis, x and y. Like I said, I'm not a math student so, I'm not sure how to define it in mathematical terms. basically it would look like an orange but with smaller and smaller pieces at, 90º, 180º, 270º, and 0º.
---
EDIT (niles):
Are you looking for formulas to parametrize these various great circles (so that you can plot them with sage)? If so, maybe rotation matrices are one easy way to produce them. You could start with a great circle whose parametrization you know (e.g. the one in the x-z plane) and then get others by rotating about the z-axis, say 45º, 67.5º, 78.75º, etc. Is that something like what you're looking for?
If so, the Wikipedia article for [rotation matrices](http://en.wikipedia.org/wiki/Rotation_matrix#Three_dimensions) looks useful. I believe you can plot parametric curves with sage, and apply arbitrary transformation matrices to them. For starters, here's a circle:
sage: u = var('u')
sage: parametric_plot3d( (cos(u), 0, sin(u)), (u, 0, 2*pi))
---
EDIT (dividenot):
Thanks for the reply. That sounds exactly what I'm looking to do. I must say though, I'm somewhat confused about the ask/answer system here. Initially I was looking for some kind of forum where I could have a discussion or look up any needed information but ask.sagemath.org was the closest thing I could find. Is editing the message like this the best way to have a discussion?
I looked at the Wikipedia article on rotation matrices. I suspect that SAGE doesn't have a command for rotation matrices so I would have to make an array defining my own range. And call the values of each circle from the matrix. Does that sound like a good way to go about it?Wed, 01 Dec 2010 11:17:24 +0100https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/Answer by niles for <p>Hi,</p>
<p>I'm working on a project and found that sage may be the best program to help. Information can be found at <a href="http://vividdynamics.com">vividdynamics.com</a>. I'm not a math student but study it as a hobby(mainly geometry) and have some art backround.</p>
<p>I'm looking for a way to generate a sphere with great circles plotted at cumulatively smaller intervals as they get closer to axis, x and y. Like I said, I'm not a math student so, I'm not sure how to define it in mathematical terms. basically it would look like an orange but with smaller and smaller pieces at, 90º, 180º, 270º, and 0º.</p>
<hr/>
<p>EDIT (niles):</p>
<p>Are you looking for formulas to parametrize these various great circles (so that you can plot them with sage)? If so, maybe rotation matrices are one easy way to produce them. You could start with a great circle whose parametrization you know (e.g. the one in the x-z plane) and then get others by rotating about the z-axis, say 45º, 67.5º, 78.75º, etc. Is that something like what you're looking for?</p>
<p>If so, the Wikipedia article for <a href="http://en.wikipedia.org/wiki/Rotation_matrix#Three_dimensions">rotation matrices</a> looks useful. I believe you can plot parametric curves with sage, and apply arbitrary transformation matrices to them. For starters, here's a circle:</p>
<pre><code>sage: u = var('u')
sage: parametric_plot3d( (cos(u), 0, sin(u)), (u, 0, 2*pi))
</code></pre>
<hr/>
<p>EDIT (dividenot):</p>
<p>Thanks for the reply. That sounds exactly what I'm looking to do. I must say though, I'm somewhat confused about the ask/answer system here. Initially I was looking for some kind of forum where I could have a discussion or look up any needed information but <a href="http://ask.sagemath.org">ask.sagemath.org</a> was the closest thing I could find. Is editing the message like this the best way to have a discussion?</p>
<p>I looked at the Wikipedia article on rotation matrices. I suspect that SAGE doesn't have a command for rotation matrices so I would have to make an array defining my own range. And call the values of each circle from the matrix. Does that sound like a good way to go about it?</p>
https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?answer=11808#post-id-11808Hi dividenot,
> ... I must say though, I'm somewhat
> confused about the ask/answer system
> here. ... Is editing the message like
> this the best way to have a
> discussion?
>
We're sort of figuring out how this site can be useful as we go -- it's not that old yet. Only people with sufficiently hight karma can edit the wiki question, so in general it's not the best way to go; I did it in this case because my comments didn't really seem like an "answer".
> Initially I was looking for some kind
> of forum where I could have a
> discussion or look up any needed
> information but ask.sagemath.org was
> the closest thing I could find.
There are also the `sage-*` google groups -- the two most relevant are probably [sage-support](http://groups.google.com/group/sage-support) and [sage-devel](http://groups.google.com/group/sage-devel). They're both very active, and the only down side is that you have to be approved to join the groups; that usually takes less than a day though.
---
Now on to something more like an answer: Looking at the documentation for [3d graphics](http://www.sagemath.org/doc/reference/plot3d.html), I found that Sage has support for alternate (non-cartesian) coordinate systems; e.g. [spherical coordinates](http://www.sagemath.org/doc/reference/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.Spherical) -- no rotation matrices needed. To me, the documentation was a little confusing (especially the part where, I think, the words *dependent* and *independent* are interchanged!), but eventually I realized that you can plot a "segment" of a sphere simply with:
sage: T = Spherical('radius', ['azimuth', 'inclination'])
sage: var('theta, phi')
sage: plot3d(2, (theta, 0, pi/4), (phi, 0, pi), transformation=T, aspect_ratio=(1,1,1))
![spherical section](/upfiles/12912628393217039.jpg)
Now comes the real fun: you can make a very narrow section with, e.g.
sage: plot3d(2, (theta, 0,.01), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1))
and, even better, define a function which returns the plot starting at theta=t:
sage: cp = lambda t: plot3d(2, (theta, t, t+.01), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1))
You can draw multiple plots in the same picture by adding, or, if you have a lot of things to add, use summation over a range!
sage: many_circles = cp(0) + sum(cp(pi/(2^n)) for n in range(1,7))
sage: many_circles.show()
![image description](/upfiles/1291263147537094.jpg)Wed, 01 Dec 2010 23:16:00 +0100https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?answer=11808#post-id-11808Comment by niles for <p>Hi dividenot,</p>
<blockquote>
<p>... I must say though, I'm somewhat
confused about the ask/answer system
here. ... Is editing the message like
this the best way to have a
discussion?</p>
</blockquote>
<p>We're sort of figuring out how this site can be useful as we go -- it's not that old yet. Only people with sufficiently hight karma can edit the wiki question, so in general it's not the best way to go; I did it in this case because my comments didn't really seem like an "answer".</p>
<blockquote>
<p>Initially I was looking for some kind
of forum where I could have a
discussion or look up any needed
information but <a href="http://ask.sagemath.org">ask.sagemath.org</a> was
the closest thing I could find.</p>
</blockquote>
<p>There are also the <code>sage-*</code> google groups -- the two most relevant are probably <a href="http://groups.google.com/group/sage-support">sage-support</a> and <a href="http://groups.google.com/group/sage-devel">sage-devel</a>. They're both very active, and the only down side is that you have to be approved to join the groups; that usually takes less than a day though.</p>
<hr/>
<p>Now on to something more like an answer: Looking at the documentation for <a href="http://www.sagemath.org/doc/reference/plot3d.html">3d graphics</a>, I found that Sage has support for alternate (non-cartesian) coordinate systems; e.g. <a href="http://www.sagemath.org/doc/reference/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.Spherical">spherical coordinates</a> -- no rotation matrices needed. To me, the documentation was a little confusing (especially the part where, I think, the words <em>dependent</em> and <em>independent</em> are interchanged!), but eventually I realized that you can plot a "segment" of a sphere simply with:</p>
<pre><code>sage: T = Spherical('radius', ['azimuth', 'inclination'])
sage: var('theta, phi')
sage: plot3d(2, (theta, 0, pi/4), (phi, 0, pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p><img alt="spherical section" src="/upfiles/12912628393217039.jpg"/></p>
<p>Now comes the real fun: you can make a very narrow section with, e.g.</p>
<pre><code>sage: plot3d(2, (theta, 0,.01), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p>and, even better, define a function which returns the plot starting at theta=t:</p>
<pre><code>sage: cp = lambda t: plot3d(2, (theta, t, t+.01), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p>You can draw multiple plots in the same picture by adding, or, if you have a lot of things to add, use summation over a range!</p>
<pre><code>sage: many_circles = cp(0) + sum(cp(pi/(2^n)) for n in range(1,7))
sage: many_circles.show()
</code></pre>
<p><img alt="image description" src="/upfiles/1291263147537094.jpg"/></p>
https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?comment=22460#post-id-22460oh, thanks for catching that -- I've updated the answer now :)Thu, 02 Dec 2010 09:49:44 +0100https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?comment=22460#post-id-22460Comment by dividenot for <p>Hi dividenot,</p>
<blockquote>
<p>... I must say though, I'm somewhat
confused about the ask/answer system
here. ... Is editing the message like
this the best way to have a
discussion?</p>
</blockquote>
<p>We're sort of figuring out how this site can be useful as we go -- it's not that old yet. Only people with sufficiently hight karma can edit the wiki question, so in general it's not the best way to go; I did it in this case because my comments didn't really seem like an "answer".</p>
<blockquote>
<p>Initially I was looking for some kind
of forum where I could have a
discussion or look up any needed
information but <a href="http://ask.sagemath.org">ask.sagemath.org</a> was
the closest thing I could find.</p>
</blockquote>
<p>There are also the <code>sage-*</code> google groups -- the two most relevant are probably <a href="http://groups.google.com/group/sage-support">sage-support</a> and <a href="http://groups.google.com/group/sage-devel">sage-devel</a>. They're both very active, and the only down side is that you have to be approved to join the groups; that usually takes less than a day though.</p>
<hr/>
<p>Now on to something more like an answer: Looking at the documentation for <a href="http://www.sagemath.org/doc/reference/plot3d.html">3d graphics</a>, I found that Sage has support for alternate (non-cartesian) coordinate systems; e.g. <a href="http://www.sagemath.org/doc/reference/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.Spherical">spherical coordinates</a> -- no rotation matrices needed. To me, the documentation was a little confusing (especially the part where, I think, the words <em>dependent</em> and <em>independent</em> are interchanged!), but eventually I realized that you can plot a "segment" of a sphere simply with:</p>
<pre><code>sage: T = Spherical('radius', ['azimuth', 'inclination'])
sage: var('theta, phi')
sage: plot3d(2, (theta, 0, pi/4), (phi, 0, pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p><img alt="spherical section" src="/upfiles/12912628393217039.jpg"/></p>
<p>Now comes the real fun: you can make a very narrow section with, e.g.</p>
<pre><code>sage: plot3d(2, (theta, 0,.01), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p>and, even better, define a function which returns the plot starting at theta=t:</p>
<pre><code>sage: cp = lambda t: plot3d(2, (theta, t, t+.01), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p>You can draw multiple plots in the same picture by adding, or, if you have a lot of things to add, use summation over a range!</p>
<pre><code>sage: many_circles = cp(0) + sum(cp(pi/(2^n)) for n in range(1,7))
sage: many_circles.show()
</code></pre>
<p><img alt="image description" src="/upfiles/1291263147537094.jpg"/></p>
https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?comment=22461#post-id-22461Just noticed the post a comment button. *feeling kind of silly now*. Thanks alot for the help. I noticed that before evaluating sage: T = Spherical('radius', ['azimuth', 'inclination'])
sage: plot3d(2, (theta, 0, pi/4), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1)) I had to define theta and phi. After that everything worked smoothly. That helps a lot. Thanks again!Thu, 02 Dec 2010 08:47:49 +0100https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?comment=22461#post-id-22461Comment by Jason Grout for <p>Hi dividenot,</p>
<blockquote>
<p>... I must say though, I'm somewhat
confused about the ask/answer system
here. ... Is editing the message like
this the best way to have a
discussion?</p>
</blockquote>
<p>We're sort of figuring out how this site can be useful as we go -- it's not that old yet. Only people with sufficiently hight karma can edit the wiki question, so in general it's not the best way to go; I did it in this case because my comments didn't really seem like an "answer".</p>
<blockquote>
<p>Initially I was looking for some kind
of forum where I could have a
discussion or look up any needed
information but <a href="http://ask.sagemath.org">ask.sagemath.org</a> was
the closest thing I could find.</p>
</blockquote>
<p>There are also the <code>sage-*</code> google groups -- the two most relevant are probably <a href="http://groups.google.com/group/sage-support">sage-support</a> and <a href="http://groups.google.com/group/sage-devel">sage-devel</a>. They're both very active, and the only down side is that you have to be approved to join the groups; that usually takes less than a day though.</p>
<hr/>
<p>Now on to something more like an answer: Looking at the documentation for <a href="http://www.sagemath.org/doc/reference/plot3d.html">3d graphics</a>, I found that Sage has support for alternate (non-cartesian) coordinate systems; e.g. <a href="http://www.sagemath.org/doc/reference/sage/plot/plot3d/plot3d.html#sage.plot.plot3d.plot3d.Spherical">spherical coordinates</a> -- no rotation matrices needed. To me, the documentation was a little confusing (especially the part where, I think, the words <em>dependent</em> and <em>independent</em> are interchanged!), but eventually I realized that you can plot a "segment" of a sphere simply with:</p>
<pre><code>sage: T = Spherical('radius', ['azimuth', 'inclination'])
sage: var('theta, phi')
sage: plot3d(2, (theta, 0, pi/4), (phi, 0, pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p><img alt="spherical section" src="/upfiles/12912628393217039.jpg"/></p>
<p>Now comes the real fun: you can make a very narrow section with, e.g.</p>
<pre><code>sage: plot3d(2, (theta, 0,.01), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p>and, even better, define a function which returns the plot starting at theta=t:</p>
<pre><code>sage: cp = lambda t: plot3d(2, (theta, t, t+.01), (phi, 0, 2*pi), transformation=T, aspect_ratio=(1,1,1))
</code></pre>
<p>You can draw multiple plots in the same picture by adding, or, if you have a lot of things to add, use summation over a range!</p>
<pre><code>sage: many_circles = cp(0) + sum(cp(pi/(2^n)) for n in range(1,7))
sage: many_circles.show()
</code></pre>
<p><img alt="image description" src="/upfiles/1291263147537094.jpg"/></p>
https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?comment=22463#post-id-22463You could also use the spherical_plot3d. Also, I opened up a trac ticket to improve the independent/dependent mistakes in the documentation: http://trac.sagemath.org/sage_trac/ticket/10367Thu, 02 Dec 2010 05:05:38 +0100https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?comment=22463#post-id-22463Answer by Paul Bryan for <p>Hi,</p>
<p>I'm working on a project and found that sage may be the best program to help. Information can be found at <a href="http://vividdynamics.com">vividdynamics.com</a>. I'm not a math student but study it as a hobby(mainly geometry) and have some art backround.</p>
<p>I'm looking for a way to generate a sphere with great circles plotted at cumulatively smaller intervals as they get closer to axis, x and y. Like I said, I'm not a math student so, I'm not sure how to define it in mathematical terms. basically it would look like an orange but with smaller and smaller pieces at, 90º, 180º, 270º, and 0º.</p>
<hr/>
<p>EDIT (niles):</p>
<p>Are you looking for formulas to parametrize these various great circles (so that you can plot them with sage)? If so, maybe rotation matrices are one easy way to produce them. You could start with a great circle whose parametrization you know (e.g. the one in the x-z plane) and then get others by rotating about the z-axis, say 45º, 67.5º, 78.75º, etc. Is that something like what you're looking for?</p>
<p>If so, the Wikipedia article for <a href="http://en.wikipedia.org/wiki/Rotation_matrix#Three_dimensions">rotation matrices</a> looks useful. I believe you can plot parametric curves with sage, and apply arbitrary transformation matrices to them. For starters, here's a circle:</p>
<pre><code>sage: u = var('u')
sage: parametric_plot3d( (cos(u), 0, sin(u)), (u, 0, 2*pi))
</code></pre>
<hr/>
<p>EDIT (dividenot):</p>
<p>Thanks for the reply. That sounds exactly what I'm looking to do. I must say though, I'm somewhat confused about the ask/answer system here. Initially I was looking for some kind of forum where I could have a discussion or look up any needed information but <a href="http://ask.sagemath.org">ask.sagemath.org</a> was the closest thing I could find. Is editing the message like this the best way to have a discussion?</p>
<p>I looked at the Wikipedia article on rotation matrices. I suspect that SAGE doesn't have a command for rotation matrices so I would have to make an array defining my own range. And call the values of each circle from the matrix. Does that sound like a good way to go about it?</p>
https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?answer=11814#post-id-11814I don't know if you can do it using plot3d via a spherical transform, but you can just do a 3 dimensional parametric plot directly providing the transformation as follows:
var('phi')
r = 1
theta = 0
parametric_plot3d((r*cos(theta)*sin(phi), r*sin(theta)*sin(phi), r*cos(phi)), (phi, 0, 2*pi))
Then as above, you can create a function and show many circles
cp = lambda theta: parametric_plot3d((r*cos(theta)*sin(phi), r*sin(theta)*sin(phi), r*cos(phi)), (phi, 0, 2*pi))
many_circles = cp(0) + sum(cp(pi/(2^n)) for n in range(1,7)) + sum(cp(-pi/(2^n)) for n in range(1,7))
many_circles.show()
![image description](/upfiles/12914799142108112.jpg)
Sat, 04 Dec 2010 05:10:14 +0100https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?answer=11814#post-id-11814Answer by dividenot for <p>Hi,</p>
<p>I'm working on a project and found that sage may be the best program to help. Information can be found at <a href="http://vividdynamics.com">vividdynamics.com</a>. I'm not a math student but study it as a hobby(mainly geometry) and have some art backround.</p>
<p>I'm looking for a way to generate a sphere with great circles plotted at cumulatively smaller intervals as they get closer to axis, x and y. Like I said, I'm not a math student so, I'm not sure how to define it in mathematical terms. basically it would look like an orange but with smaller and smaller pieces at, 90º, 180º, 270º, and 0º.</p>
<hr/>
<p>EDIT (niles):</p>
<p>Are you looking for formulas to parametrize these various great circles (so that you can plot them with sage)? If so, maybe rotation matrices are one easy way to produce them. You could start with a great circle whose parametrization you know (e.g. the one in the x-z plane) and then get others by rotating about the z-axis, say 45º, 67.5º, 78.75º, etc. Is that something like what you're looking for?</p>
<p>If so, the Wikipedia article for <a href="http://en.wikipedia.org/wiki/Rotation_matrix#Three_dimensions">rotation matrices</a> looks useful. I believe you can plot parametric curves with sage, and apply arbitrary transformation matrices to them. For starters, here's a circle:</p>
<pre><code>sage: u = var('u')
sage: parametric_plot3d( (cos(u), 0, sin(u)), (u, 0, 2*pi))
</code></pre>
<hr/>
<p>EDIT (dividenot):</p>
<p>Thanks for the reply. That sounds exactly what I'm looking to do. I must say though, I'm somewhat confused about the ask/answer system here. Initially I was looking for some kind of forum where I could have a discussion or look up any needed information but <a href="http://ask.sagemath.org">ask.sagemath.org</a> was the closest thing I could find. Is editing the message like this the best way to have a discussion?</p>
<p>I looked at the Wikipedia article on rotation matrices. I suspect that SAGE doesn't have a command for rotation matrices so I would have to make an array defining my own range. And call the values of each circle from the matrix. Does that sound like a good way to go about it?</p>
https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?answer=11816#post-id-11816 var('phi')
r = 1
theta = 0
cp = lambda theta: parametric_plot3d((r*cos(theta)*sin(phi), r*sin(theta)*sin(phi),
r*cos(phi)), (phi, 0, pi*2)) + parametric_plot3d((r*sin(theta)*sin(phi),
r*cos(theta)*sin(phi), r*cos(phi)), (phi, 0, pi*2))
many_circles = cp(0) + sum(cp(pi/(2^n)) for n in range(1,7)) + sum(cp(-pi/(2^n))
for n in range(1,7));
many_circles
I found that I don't have to use .show. This is more like what I've been trying to do:
[http://t2nb.math.washington.edu:8000/home/pub/53/](http://t2nb.math.washington.edu:8000/home/pub/53/)
Thanks again for the helpSat, 04 Dec 2010 18:12:37 +0100https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?answer=11816#post-id-11816Comment by Evgeny for <pre><code>var('phi')
r = 1
theta = 0
cp = lambda theta: parametric_plot3d((r*cos(theta)*sin(phi), r*sin(theta)*sin(phi),
r*cos(phi)), (phi, 0, pi*2)) + parametric_plot3d((r*sin(theta)*sin(phi),
r*cos(theta)*sin(phi), r*cos(phi)), (phi, 0, pi*2))
many_circles = cp(0) + sum(cp(pi/(2^n)) for n in range(1,7)) + sum(cp(-pi/(2^n))
for n in range(1,7));
many_circles
</code></pre>
<p>I found that I don't have to use .show. This is more like what I've been trying to do:</p>
<p><a href="http://t2nb.math.washington.edu:8000/home/pub/53/">http://t2nb.math.washington.edu:8000/home/pub/53/</a></p>
<p>Thanks again for the help</p>
https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?comment=22457#post-id-22457karma is not awarded for the wiki posts, sorry it's not self evident. I've added 10 points manually to compensate for the damages.Sat, 04 Dec 2010 19:08:31 +0100https://ask.sagemath.org/question/7785/new-project-looking-for-help-plotting-great-circles/?comment=22457#post-id-22457