Skip to main content
deleted 3 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Here is the code for the rotation function (in a file called geo.py):

If I can get this below 3e-06s for 4 vertices that would be phenomenally helpful. Thanks!

UPDATE 1:UPDATE 1:

Here is the code for the rotation function (in a file called geo.py)

If I can get this below 3e-06s for 4 vertices that would be phenomenally helpful. Thanks!

UPDATE 1:

Here is the code for the rotation function (in a file called geo.py):

If I can get this below 3e-06s for 4 vertices that would be phenomenally helpful.

UPDATE 1:

edited tags; edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

How can this python code be made faster? Optimize vector rotation

added 784 characters in body
Source Link

UPDATE 1:

Just found an optimization; in the list comprehension I say (x, y) every iteration, meaning I have to rebuild the tuple every single iteration. Removing that shaves the time down to between 7e-06 and 6.9e-06s for 4 vertices.

def rotate2(self, angle, anchor=(0, 0)):
    # Avg runtime for 4 vertices: 7.0e-06s
    # Best time of 50 tests: 6.92e-06s
    orx, ory = self._origin
    x, y = anchor
    if x or y:
        # Default values of x and y (0, 0) indicate
        # for the method to use the frame origin as
        # the anchor.
        x = x - orx
        y = y - ory
        anchor = x, y
    _rot = geo.rotate_vector
    self._offsets = [_rot(v, angle, anchor) for v in self._offsets]

UPDATE 1:

Just found an optimization; in the list comprehension I say (x, y) every iteration, meaning I have to rebuild the tuple every single iteration. Removing that shaves the time down to between 7e-06 and 6.9e-06s for 4 vertices.

def rotate2(self, angle, anchor=(0, 0)):
    # Avg runtime for 4 vertices: 7.0e-06s
    # Best time of 50 tests: 6.92e-06s
    orx, ory = self._origin
    x, y = anchor
    if x or y:
        # Default values of x and y (0, 0) indicate
        # for the method to use the frame origin as
        # the anchor.
        x = x - orx
        y = y - ory
        anchor = x, y
    _rot = geo.rotate_vector
    self._offsets = [_rot(v, angle, anchor) for v in self._offsets]
Source Link
Loading