# ogre-ssao / python / gen_sphere_points.py

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68``` ```#!/usr/bin/env python from __future__ import division import random as r import math as m import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def norm(x, y, z): return m.sqrt(x*x + y*y + z*z) def normalize(x, y, z): n = norm(x, y, z) return (x/n, y/n, z/n) def normalize_and_scale(x, y, z): s = r.random() normalized = normalize(x, y, z) return (normalized[0]*s, normalized[1]*s, normalized[2]*s) def make_colors(xs, yz, zs): def make_RBGA_string(x, y, z): return "#%02hx%02hx%02hx" % tuple([int(v*255) for v in (x, y, z)]) return [make_RBGA_string(x, y, z) for (x, y, z) in zip(xs, ys, zs)] def make_scatterplot(xs, ys, zs): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.scatter(xs, ys, zs, s=50)#, c=make_colors(xs, ys, zs)) plt.show() if __name__ == '__main__': N = 64 xs, ys, zs = [], [], [] for i in range(N): x = r.uniform(0, 1) y = r.uniform(0, 1) z = r.uniform(0, 1) print x, y, z sx, sy, sz = x, y, z #normalize_and_scale(x, y, z) xs.append(sx) ys.append(sy) zs.append(sz) make_scatterplot(xs, ys, xs) ```