Visual Python

by syoyo

randunitvec.png

I found a good visualization tool powerd by Python, vpython
(See quite nice application of vpython for teaching physics)

The above image shows random unit vectors and is generate by following python script.
It’s quite simple to code, and you can drag/zoom the scene without describing anything about mouse handling & screen drawing.

Wouldn’t it be nice to use vpython for visually validate graphics algorithms(e.g. path muatation for MLT)?


from visual import *

import math
import random

# Generate 100 random unit vector on upper hem-sphere
for n in range(100):
    theta = math.sqrt(random.random())
    phi   = 2.0 * math.pi * random.random()

    x     = math.cos(phi) * theta
    z     = math.sin(phi) * theta
    y     = math.sqrt(1.0 - theta * theta)

    pointer = arrow(pos=(0.0, 0.0, 0.0), axis=(x, y, z), shaftwidth=0.01)

Advertisements