- #1

minger

Science Advisor

- 1,495

- 1

## Main Question or Discussion Point

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:

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.

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)
```

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.