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: 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
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: 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)
2009-07-08 09:09
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.
2009-07-08 11:05
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.
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
Mike
zscs
Deev/Onslaught
LKP/CFN
kbs/Pht/Lxt
Aomeba/Artline Desig..
Lazycow
TheRyk/MYD!
t0m3000/hf^boom!^ibx
Case/Padua
St0rmfr0nt/Quantum
MWR/Visdom
Chesoner/House Designs
Guests online: 110
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Original Suppliers
1 Derbyshire Ram  (9.7)
2 Fungus  (9.3)
3 Black Beard  (9.2)
4 Baracuda  (9.2)
5 hedning  (9.1)

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