Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Point rotation
2009-07-07 20:56
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?
2009-07-07 21:11
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?
2009-07-08 06:41
HCL

Registered: Feb 2003
Posts: 727
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
2009-07-08 07:20
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?
2009-07-08 08:06
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.
2009-07-08 08:25
Oswald

Registered: Apr 2002
Posts: 5076
if everything is fixed, and only the angle is changing you can pretty much precalculate everything. (one sine & cosine table for each radius used)
2009-07-08 09:09
yago

Registered: May 2002
Posts: 332
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.
2009-07-08 11:05
Jetboy

Registered: Jul 2006
Posts: 269
How about using complex numbers? That will give you rotation and scaling in one pass with only addition and multiplication used.
2009-07-08 11:41
Graham
Account closed

Registered: Dec 2002
Posts: 990
Which only gives you an advantage in notation but not in 6502 code.
2009-07-08 12:25
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

2009-07-08 18:20
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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
theK/ATL
eryngi
Exploding Fi../Techn..
Guests online: 97
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 Uncensored  (9.6)
7 Wonderland XIV  (9.6)
8 Comaland 100%  (9.6)
9 No Bounds  (9.6)
10 Unboxed  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Morph  (9.5)
8 Dawnfall V1.1  (9.5)
9 Onscreen 5k  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Performers  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Jeroen Tel  (9.7)
3 Stinsen  (9.6)
4 Mutetus  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.062 sec.