Code Monkey home page Code Monkey logo

Comments (2)

Uvar avatar Uvar commented on July 23, 2024

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.

wolph avatar wolph commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.