| |
Axel Account closed
Registered: Apr 2006 Posts: 42 |
Point rotation
How can I rotate point by fixed axis? how calculate new x and new y coordinates in assembler? |
|
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Same as in any other CPU or language. What exactly are you asking? How it works mathematically, or how to implement it efficiently in assembler or perhaps both?
|
| |
HCL
Registered: Feb 2003 Posts: 728 |
x = x0 * cos(a) + y0 * sin(a)
y = y0 * cos(a) - x0 * sin(a)
..causes rotation around one axis. So, basically you need a sin/cos, and a mul. The rest is on http://codebase64.org/doku.php |
| |
Axel Account closed
Registered: Apr 2006 Posts: 42 |
Ok thanks, but I need to rotate many points using one angle around one axis How to do this efficiently? |
| |
ready.
Registered: Feb 2003 Posts: 441 |
look at http://noname.c64.org/csdb/release/?id=41457, the dot plot part (flower part, I still have the final flower part to release......)
There I rotate many points around around the XY origin, it is a 2-D XY rotation.
The basic technique used there is, as said:
x = x0 * cos(a) + y0 * sin(a)
y = y0 * cos(a) - x0 * sin(a)
so, one cos look up table and one sin look up table. Then an efficient multiplication routine:
a*b = f(a+b) - f(a-b), f(x) = x^2/4
Look here: fixed point multiplication
or codebase, as said.
PM me if you want some code examples.
Ready.
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
if everything is fixed, and only the angle is changing you can pretty much precalculate everything. (one sine & cosine table for each radius used) |
| |
yago
Registered: May 2002 Posts: 333 |
If the angle is fixed, you can rotate without using cosine, sinus or multiplication.
NEW X = OLD X - epsilon * OLD Y
NEW Y = OLD Y + epsilon * NEW(!) X
http://www.inwap.com/pdp10/hbaker/hakmem/hacks.html#item149
epsilon can be power of 2, to change speed of rotation, use different epsilons.
this is used for example in Stars and Stabbers
PS: For this to work, you must used signed bytes, though. |
| |
Jetboy
Registered: Jul 2006 Posts: 337 |
How about using complex numbers? That will give you rotation and scaling in one pass with only addition and multiplication used. |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
Which only gives you an advantage in notation but not in 6502 code. |
| |
Slammer
Registered: Feb 2004 Posts: 416 |
Quote: Ok thanks, but I need to rotate many points using one angle around one axis How to do this efficiently?
If you really mean ONE axis so you dont want to rotate the rotated point around another axis afterwards, then you could represent the points as a length(l) and an angle(pa). Now you can reduce the calculation to:
x = l*cos(a+pa)
y = l*sin(a+pa)
where a is the angle you want to rotate
|
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Or you do it like the dot-plot parts out there. Assume integer based input coords.
Per frame look up the cos and sin value of your angle.
c[0] = cos(a)
s[0] = sin(a)
Add these by themselfes a couple of times to get *2, *3, *4 etc to whatever you need depending on your input set size and store into the rest of the c[] and s[] arrays.
Now compute the a coord X,Y simple do:
x = c[X] + s[Y]
y = c[Y] - s[X]
So, for instance, if you know u have input coords ranging from 0..31 in both directions u need to do about 64 adds per frame to calculate the c[] and s[] arrays. Then the rest is simple additions.
|
... 5 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 - Next |