Created
September 21, 2012 17:49
-
-
Save pcote/3762911 to your computer and use it in GitHub Desktop.
An example of list comprehensions in action for solving a linear algebra problem for making a set of verts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_step(width, base_level, step_height, num_sides): | |
axis = [0,0,-1] | |
PI2 = pi * 2 | |
rad = width / 2 | |
init_vector = Vector([rad, 0, base_level]) | |
quat_angles = [(cur_side/num_sides) * PI2 | |
for cur_side in range(num_sides)] | |
quaternions = [Quaternion(axis, quat_angle) | |
for quat_angle in quat_angles] | |
vectors = [quaternion * init_vector | |
for quaternion in quaternions] | |
bottom_list = [(vec.x, vec.y, vec.z) | |
for vec in vectors] | |
top_list = [(vec.x, vec.y, vec.z+step_height) | |
for vec in vectors] | |
full_list = bottom_list + top_list | |
return full_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment