-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathorient.py
36 lines (25 loc) · 1.42 KB
/
orient.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
import numpy as np
import gtransform
'''
Code to orient the initial geometry centered upon the geometric origin
Then scales the object to fit within the viewing window and a supplied print bed size
Evan Chodora, 2018
https://github.com/evanchodora/stl-slicer
'''
def to_origin(geometry):
# Compute object dimensions and distance from the origin
max_size = np.max(geometry, axis=0) # Max X,Y,Z values of the object
min_size = np.min(geometry, axis=0) # Min X,Y,Z values of the object
x_trans = 0 - 0.5*(max_size[0]+min_size[0]) # Avg X distance from the origin (center of the object)
y_trans = 0 - 0.5*(max_size[1]+min_size[1]) # Avg Y distance from the origin (center of the object)
z_trans = 0 - 0.5*(max_size[2]+min_size[2]) # Avg Z distance from the origin (center of the object)
geometry = gtransform.translate(geometry, x_trans, y_trans, z_trans) # Translate object accordingly to origin
return geometry
def fit_bed(geometry, xdim, ydim, zdim):
# Scale object to fit in printing space (8in x 8in x 6in)
max_size = np.max(geometry, axis=0) # Max X,Y,Z values of the object
# Compute object scaling based on the minimum ratio between the print bed dimensions and the object size
scale = min(xdim/max_size[0], ydim/max_size[1], zdim/max_size[2])
geometry = gtransform.scale(geometry, 1 / scale) # Apply global scaling with appropriate factor
return geometry