Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Setting coordinates for sphere

I have a code that produces a sphere. I want to change the coordinates in which the sphere spawns

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
from matplotlib import cm
from matplotlib import animation
import pandas as pd
    
fig = plt.figure(facecolor='black')
ax = plt.axes(projection = "3d")

u = np.linspace(0, 2*np.pi, 100)
v = np.linspace(0, np.pi, 100)
r = 10

ax.set_xlim(0, 60)
ax.set_ylim(0, 60)
ax.set_zlim(0, 60)

x = r * np.outer(np.cos(u), np.sin(v))
y = r * np.outer(np.sin(u), np.sin(v))
z = r * np.outer(np.ones(np.size(u)), np.cos(v))

def init():
    ax.plot_surface(x,y,z)
    return fig,

def animate(i):
    ax.view_init(elev = 20, azim = i*4)

ani = animation. FuncAnimation(fig, animate, init_func = init, frames = 90, interval = 299)


plt.show()

So for instance, I want the sphere to be drawn in the coordinates (10,10,10)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Easy, just an offset to x, y, z, like this:

x = r * np.outer(np.cos(u), np.sin(v)) + 10
y = r * np.outer(np.sin(u), np.sin(v)) + 10
z = r * np.outer(np.ones(np.size(u)), np.cos(v)) + 10
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading