Rotating a Point in Space, Function of time

Click For Summary

Discussion Overview

The discussion revolves around the problem of efficiently rotating a grid of points in space around the x-axis, focusing on computational methods and optimizations. Participants explore mathematical approaches, particularly the use of rotation matrices, to improve performance in a subroutine that handles large datasets.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Exploratory

Main Points Raised

  • One participant describes a method for rotating points using trigonometric functions but notes performance issues due to the computational cost of square roots and inverse trig functions.
  • Another participant suggests using rotation matrices to perform the rotation more efficiently, emphasizing that the same rotation matrix can be reused for all points, thus reducing the need for repetitive calculations.
  • A later reply proposes simplifying the problem by using a 2D rotation matrix instead of a 3D one, given that the rotation is around a single axis, and discusses adjusting the approach to account for angular velocity over time.
  • Participants mention the potential for matrix multiplication packages to enhance computational efficiency when dealing with large numbers of points.

Areas of Agreement / Disagreement

Participants generally agree on the utility of rotation matrices for improving computational efficiency, but there is no consensus on the best approach to implement the rotation, particularly regarding the dimensionality of the rotation (2D vs. 3D) and the handling of angular velocity.

Contextual Notes

Participants express uncertainty about the implications of using 2D versus 3D rotation matrices and the potential numerical issues related to point displacement during rotation. There are also mentions of dependencies on specific mathematical definitions and computational methods.

Who May Find This Useful

This discussion may be useful for individuals working on computational geometry, computer graphics, or simulations involving rotational dynamics, particularly those interested in optimizing performance for large datasets.

minger
Science Advisor
Messages
1,494
Reaction score
2
Hi guys, I have a problem that's bugging me. I am writing a subroutine, which basically takes a grid (collection of points in space), and rotates it around the x-axis at some given rotational velocity. I was doing it a very easy way. Basically:

Code:
x0 = 0.0
y0 = 0.0
dx = x - x0
dy = y - y0
radius = sqrt(dx*dx + dy*dy)
theta = atan(dy/dx)
theta = theta + dtheta
x = radius*cos(theta)
y = radius*sin(theta)

This works great, however it's very slow. To compute square roots and inverse trig functions in a computer code is very tedious, and when you need to do it for thousands or millions of gridpoints, it can take forever.

My idea was to just write a function for the gridpoints as a function of time alone. I won't be able to store any additional information, such as original or previous position. I had an idea of some sort of phase angle, and I think that would require that.

Also, I cannot simply find the velocity, and then calculate the displacement, and therefore new position, because apparently there are numerical problems and the grid could start to "walk" away from each other.

Hopefully I've explained this well enough, I appreciate any help.
 
Physics news on Phys.org
How much linear algebra do you know?
 
A bit. I'm finishing up my master's of science in Mech. Engineering. I have math background all the way through non-linear, high-order, transient partial diff. eqs.
 
Really, What school?
 
Ok, well hopefully this will make some sense then. Consider a single point, [itex]x_0,y_0,z_0[/itex] that gets rotated to x,y,z. Writing these points in vector notation,
[tex]\vec{x}_0 = \left(x_0,y_0,z_0\right)[/tex]

[tex]\vec{x} = \left(x,y,z\right)[/tex]

[itex]\vec{x}[/itex] and [itex]\vec{x}_0[/itex] are related by a rotation, and rotations are just a matrix multiplication. In other words, for a rotation matrix R (scroll down on the link for 3d version),
[tex]\vec{x} = R \vec{x}_0[/tex]

The key point is that the same rotation matrix will rotate any points by the same angle, so you only need to calculate R once per timestep and just reuse it for all the points. This is nice because all the trig functions and expensive computations are in R.

----

Now if you want to go crazy efficient, you could even express the rotation of all the points in a single matrix multiplication. Call all the points you want to rotate [itex]\vec{x1},\vec{x2},...,\vec{x1000000}[/itex]. Then
[tex]\vec{x1} = R \vec{x1}_0[/tex]
[tex]\vec{x2} = R \vec{x2}_0[/tex]
...
[tex]\vec{x1000000} = R \vec{x1000000}_0[/tex]

These can be combined together into a single matrix multiplication:
[tex]\left[\vec{x1} | \vec{x2} | ... | \vec{x1000000} \right] = R \left[\vec{x1}_0 | \vec{x2}_0 | \vec{x1000000}_0\right][/tex]

Then you can use a matrix multiplication package to be super efficient (mathematicians have worked very hard to figure out really really efficient ways to multiply matricies).
 
Last edited:
I think this is just what I'm looking for. It seems as though instead of using the 3D form of the equations, I will just ignore the x-component of the gridpoint location, and rotate it in R2 using the simple 2x2 rotation matrix (I assume this is fine, it doesn't make sense to me to use the 3D version if one is simply rotating around 1 axis).

I will have to change it up a little. Rather than rotation with a given speed, I'll just have to multiply the speed by the change in time and compute the d_theta.

Anyways though, I really appreciate the help maze. We have matrix operations classes in our program so I'm sure it won't be a problem to get it running fast.

Thanks again a bunch!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 33 ·
2
Replies
33
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 13 ·
Replies
13
Views
1K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 20 ·
Replies
20
Views
3K