Home > Mobile >  Setting coordinates for sphere
Setting coordinates for sphere

Time:05-07

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)

CodePudding user response:

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
  • Related