Comments (2)
In the past I used something like this, in which orient is the unit normal
of a facet which is intended to face downwards.:
def rotation(self, orient):
"This function might cause xy-plane rotation, that does not matter much"
alpha = 0.5 * math.pi - math.atan2(orient[Y], orient[X])
beta = -0.5 * math.pi - math.atan2(
orient[Z], math.sqrt(orient[X] ** 2 + orient[Y] ** 2))
sin_a = math.sin(alpha)
cos_a = math.cos(alpha)
sin_b = math.sin(beta)
cos_b = math.cos(beta)
rotation_matrix = numpy.transpose((
(cos_a, -sin_a, 0),
(cos_b * sin_a, cos_b * cos_a, -sin_b),
(sin_b * sin_a, sin_b * cos_a, cos_b),
))
return rotation_matrix
def transform(self, orient):
rotation_matrix = self.rotation(orient)
rotated_vectors = numpy.dot(self.vectors, rotation_matrix)
rotated_vectors = numpy.array(rotated_vectors, dtype='float32')
max_ = rotated_vectors.max(axis=(0, 1))
min_ = rotated_vectors.min(axis=(0, 1))
rotated_vectors[:, :, Z] -= min_[Z] # translation to have Z_min == 0. Not required per se
max_[Z] -= min_[Z]
min_[Z] -= min_[Z]
return rotated_vectors, rotation_matrix
Rotating according to a rotation matrix is as simple as taking the dot product of the data with the rotation matrix.
from numpy-stl.
For completeness I've simply split the rotation method into multiple functions right now, but you're right @Uvar, the rotations and translations could simply be combined in a single operation instead.
The transform method already supports this :)
from numpy-stl.
Related Issues (20)
- is_closed() gives false positives for simple STLs HOT 7
- stl2ascii raises a TypeError: File handles should be in binary mode - even when writing an ASCII STL. HOT 1
- Combined STL HOT 1
- How to use `test` modules HOT 1
- Z-height HOT 5
- Graph Generation is Blank HOT 1
- Parsing ASCII STL ending with "end solid" raises exception HOT 2
- about projection area HOT 1
- shape cant find HOT 1
- Save multi-part stls HOT 3
- Possible error in volume calculations HOT 4
- Can we check if two different stl files are overlapping each other HOT 1
- saving ascii STL HOT 2
- Merge STL question HOT 4
- AttributeError: module 'stl' has no attribute 'BaseStl HOT 1
- Computing the Max Z-height for double rotation HOT 3
- More info needed on stl atributes HOT 3
- the centroids of a stl file was not update after i rotated the stl file HOT 3
- How can i find linear parameters of stl model? HOT 2
- can't make image array into *.stl HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numpy-stl.