-
Notifications
You must be signed in to change notification settings - Fork 1
/
testGen.py
executable file
·69 lines (54 loc) · 2.11 KB
/
testGen.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
69
#!/usr/bin/python
import sys
import numpy as np
import math
# This file generates a cube with specified side lengths and generates the joints
# necessary to get the requested number of blocks.
# First command line argument: Output file name
# Second command line argument: Number of blocks desired
# Process command line inputs
outputFile = str(sys.argv[1])
nBlocks = float(sys.argv[2])
numberBlocks = int(nBlocks)
divisions = int(math.ceil(numberBlocks**(1/3.0)))
dl = 1.0
# dl = float(sideLength/divisions)
sideLength = divisions * dl
# Generate faces for cube
faces = np.empty([6,6], dtype=float)
faces[0] = np.array([1, 0, 0, sideLength, 0, 0])
faces[1] = np.array([0, 1, 0, sideLength, 0, 0])
faces[2] = np.array([0, 0, 1, sideLength, 0, 0])
faces[3] = np.array([-1, 0, 0, 0, 0, 0])
faces[4] = np.array([0, -1, 0, 0, 0, 0])
faces[5] = np.array([0, 0, -1, 0, 0, 0])
# Generate joints
joints_x = np.empty([divisions-1, 11], dtype=float)
joints_y = np.empty([divisions-1, 11], dtype=float)
joints_z = np.empty([divisions-1, 11], dtype=float)
for i in range(0, divisions-1):
joints_x[i] = np.array([1, 0, 0, i*dl + dl, i*dl + dl, sideLength/2.0, sideLength/2.0, 0, 0, 0, 0])
joints_y[i] = np.array([0, 1, 0, i*dl + dl, sideLength/2.0, i*dl + dl, sideLength/2.0, 0, 0, 0, 0])
joints_z[i] = np.array([0, 0, 1, i*dl + dl, sideLength/2.0, sideLength/2.0, i*dl + dl, 0, 0, 0, 0])
# Write faces to output file
f = open(outputFile,'w')
for i in range(0, faces.shape[0]):
for j in range(0, faces.shape[1]):
f.write(str(faces[i][j])+" ")
f.write("\n")
# Write symbol to show transition to joint data (Yes, this is silly... we can change it if you like!)
f.write("%\n")
# Write joints to output file
for i in range(0, joints_x.shape[0]):
for j in range(0, joints_x.shape[1]):
f.write(str(joints_x[i][j])+" ")
f.write("\n")
for i in range(0, joints_y.shape[0]):
for j in range(0, joints_y.shape[1]):
f.write(str(joints_y[i][j])+" ")
f.write("\n")
for i in range(0, joints_z.shape[0]):
for j in range(0, joints_z.shape[1]):
f.write(str(joints_z[i][j])+" ")
f.write("\n")
f.close