Testing visualization in shape with pseudo-data

Wrote this python script that generates points on a sphere in Cartesian coordinates. It then writes these coordinates with some random values with velocity (vx, vy, vz) and density (n) to a tab-delimited ascii file. You can choose the radius of the sphere, and N is number of points on the sphere. Forwarded from Martin, a stackoverflow discussion. Also I am using python3.

import random
from math import pi,sin,cos

#Creating Sphere Dataz                                                                                                                                                                                      
def createSphere(r=5, N=100):
    lst = []
    for phi in [(pi*i)/(N-1) for i in range(N)]:
        M = int(sin(phi)*(N-1))+1
        for theta in [(2*pi*i)/M for i in range(M)]:
            x = r * sin(phi) * cos(theta)
            y = r * sin(phi) * sin(theta)
            z = r * cos(phi)
            lst.append((x, y, z))
    return lst

#Opens/creates new ascii file                                                                                                                                                                               
outfile = open("test.dat", "w")

#Writes the data to the file                                                                                                                                                                                
for x,y,z in createSphere():
    rho = random.random()*1000000
    vx = random.random()*10
    vy = random.random()*100
    vz = random.random()
    print("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}".format(x,y,z,vx,vy,vz,rho), file=outfile)

#Closes the file                                                                                                                                             
outfile.close()

So the pseudo-sphere data seems to visualize just fine in Shape:

3D Module
3d module in shape
Render Module
render module in shape

Aside: I am starting to document how to use Shape, here.

Attachments (2)

Download all attachments as: .zip

Comments

No comments.