C=Hacking Issue #8

Basic and Machine Language

Moderator: Moderators

Post Reply
DrVeryEvil
Vic 20 Amateur
Posts: 69
Joined: Thu Jul 23, 2015 5:11 pm
Location: Lansing, MI, USA
Occupation: Data Analyst

C=Hacking Issue #8

Post by DrVeryEvil »

http://www.ffd2.com/fridge/chacking/c=hacking8.txt

I'm looking for help with the article: " A Different Perspective: Three-Dimensional Graphics on the C64"

Is there anyone that is familiar with this process?

Code: Select all

		[cos(z)	-sin(z)	0]		[cos(y)	  0	sin(y) ]
		        [sin(z)	cos(z)	0]	X	[  0	  1	   0      ]		=
		        [  0	  0	1]		                [-sin(y)	  0	cos(y) ]

[	cos(z)cos(y)	-sin(z)		cos(z)sin(y)	]		[	1	    0	            0	        ]
[	sin(z)cos(y)	cos(z)		sin(z)sin(y)	]	X	[	0	cos(x)	-sin(x)	]	=
[	-sin(y)		   0		cos(y)	      	        ]		[	0	sin(x)	cos(x)	]

[ cos(z)cos(y)	-sin(z)cos(x)+cos(z)sin(y)sin(x)	-sin(z)(-sin(x))+cos(z)sin(y)cos(x) ]
[ sin(z)cos(y)	cos(z)cos(x)+sin(z)sin(y)sin(x)	cos(z)(-sin(x)+sin(z)sin(y)cos(x)    ]
[  -sin(y)			cos(y)sin(x)			cos(y)cos(x)		 ]

sin(a)sin(b) = ((cos(a - b) - cos( a + b))/2
cos(a)cos(b) = ((cos(a - b) + cos(a + b))/2
sin(a)cos(b) = ((sin(a + b) + sin(a - b))/2
cos(a)sin(b) = ((sin(a + b) - sin(a - b))/2
-sin(a) = sin(-a)

A.
cos(z)cos(y) = (cos(z-y) + cos(z+y))/2
B.
sin(z)cos(y) = (sin(z+y) + sin(z-y))/2
C. 
-sin(y) = sin(-y)
 
D.
-sin(z)cos(x)  +  cos(z)sin(y)sin(x)
cos(z)sin(y)sin(x)
            ^        ^
•	sin(a)sin(b) = ((cos(a - b) - cos( a + b))/2 ; a = y, b = x
cos(z)(sin(y)sin(x)) = ((cos(z)cos(y-x)) - (cos(z)cos( y+x)))/2		
cos(z)(sin(y)sin(x)) = (cos(z)cos(y-x))/2 - (cos(z)cos( y+x))/2 

•	cos(a)cos(b) = (cos(a - b) + cos(a + b))/2; a = z, b = y( + -) x
                              (cos(z)cos(y-x))/2) = ((cos(z-(y-x)) + cos(z+(y-x)))/2	(cos(z)cos(y+x))/2 = ((cos z-(y+x)) + cos(z+(y+x)))/2
                              (cos(z-(y-x))+cos(z+(y-x)))/2 - (cos(z-(y+x))+cos(z+(y+x)))/2
                              (cos(z-y-x)-cos(z+y-x) - cos(z-y+x)+cos(z+y+x))/4
                              (cos(z-y-x)-cos(z+y-x))/4 - (cos(z-y+x)+cos(z+y+x))/4

•	(-sin(a)) = sin(-a)
-sin(z)cos(x) = sin(-z)cos(x)
sin(a)cos(b) =		 (sin(a + b) + sin(a - b))/2
	(sin(-z+x) + sin(-z-x))/2
-sin(z)cos(x)  +  cos(z)sin(y)sin(x)  = (sin(-z+x) + sin(-z-x))/2) + (cos(z-y-x) - cos(z+y-x) - cos(z-y+x) + cos(z+y+x)) / 4
 
E.
cos(z)cos(x)+sin(z)sin(y)sin(x)
  ^        ^
•	cos(a)cos(b) = ((cos(a-b) + cos(a+b))/2
        cos(z)cos(x) = ((cos(z-x) + cos(z+x))/2

cos(z)cos(x)+sin(z)sin(y)sin(x) 
                                    ^        ^
•	sin(a)sin(b) = ((cos(a-b) - (cos(a+b))/2; a = y, b = x
        sin(z)sin(y)sin(x) = sin(z)((cos(y-x) - cos(y+x))/2)
                               = (sin(z)cos(y-x) - sin(z)cos(y+x))/2
                                      ^        ^	         ^       ^
•	sin(a)cos(b) = ((sin(a+b) + sin(a-b))/2; a = z, b = y (+-) x
                              sin(z)(cos(y-x)/2) = (sin(z+(y-x)) + sin(z-(y-x)))/4		sin(z)(cos(y+x)/2) = (sin(z+(y-x)) + sin(z-(y-x)))/4
	                                                             ((sin(z+y-x) + sin(z-y-x)) - (sin(z+y-x) + sin(z-y-x)))/4
                  cos(z)cos(x)+sin(z)sin(y)sin(x) = ((cos(z-x) +cos(z+x))/2 + ((sin(z+y-x) + sin(z-y-x)) - (sin(z+y-x) + sin(z-y-x)))/4

F.
•	cos(a)sin(b) = ((sin(a+b) - sin(a-b))/2
        cos(y)sin(x) = ((sin(y+x) - sin(y-x))/2
 
G.
•	-sin(a) = sin(-a)
-sin(z)(-sin(x))+cos(z)sin(y)cos(x)
    ^          ^
sin(-z)sin(-x) + cos(z)sin(y)cos(x)
•	sin(a)sin(b) = ((cos(a - b) – (cos(a + b))/2; a = z, b = x
        sin(-z)(sin(-x) = ((cos(-z+x) - (cos(-z-x))/2
•	sin(a)cos(b) = (sin(a+b) + sin(a-b))/2; a = y, b = x
            sin(-z)(sin(-x))+cos(z)sin(y)cos(x)
                                                                  ^        ^
                            cos(z)((sin(y+x) + sin(y-x))/2)
         cos(z)sin(y+x)/2					cos(z)sin(y-x)/2
•	cos(a)sin(b) = ((sin(a+b) - sin(a-b))/2; a=z, b = y (+-) x
                (sin(z+(y+x)) - sin(z-(y+x)))/4 - (sin(z+(y-x)) - (sin(z-(y-x)))/4
                ((cos(-z+x) - (cos(-z-x))/2 + ((sin(z+(y+x)) - sin(z-(y+x)))/4) - ((sin(z+(y-x)) - (sin(z-(y-x)))/4)

First, I'm curious if my matrix math is correct.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: C=Hacking Issue #8

Post by Mike »

DrVeryEvil wrote:I'm looking for help with the article: "A Different Perspective: Three-Dimensional Graphics on the C64". Is there anyone that is familiar with this process?
Yes. Me. Probably.
[Text box with lots of math formulas omitted for brevity]

First, I'm curious if my matrix math is correct.
In the article, Steve Judd presents ideas to minimize the efforts necessary to build up a rotation matrix. He uses some clever math (angle sum and differences with sine and cosine) to eliminate multiplications. Later, fixed point arithmetics are employed to speed up the calculations further.

It's quite difficult to follow through your collection of math formulas. There might be the odd mismatch of parentheses, and the choice of x,y,z designators for angles is rather unlucky (they're better reserved for co-ordinates in 3D space):

1. At the top, the Euler rotation matrix can be found in any good math text book, although I once actually went through the chore of deriving one particular version of it - which one you get depends on the choice and order of axes you turn around.

2. The following formulas look like some continued attempts to apply the angle sum and difference theorems of sine and cosine. Unless you really know what you want, that easily can get you running round in circles - and I presume that very much happened here. No point in trying to check they're all correct.

For a start I'd suggest you plug the 2D rotation matrix into BASIC and check the graphic result of rotating a simple figure. MINIGRAFIK is a good tool for this - you can concentrate on the math details and don't need to wrap your mind around the implementation of hires graphics (for the moment at least). That being estabilished, you can progress to 3D rotation and projection, and - again! - first try this out in BASIC. With those basics made clear to yourself, you can plan to progress to a ML implementation. A rotating cube is somewhat a version of "Hello World!" for 3D graphics. :)

However, make yourselves clear that starting from scratch to something working you'll easily put 100+ hours into this.

Good Luck!

Michael
DrVeryEvil
Vic 20 Amateur
Posts: 69
Joined: Thu Jul 23, 2015 5:11 pm
Location: Lansing, MI, USA
Occupation: Data Analyst

Re: C=Hacking Issue #8

Post by DrVeryEvil »

Thank you for the help.

I know there's easier ways, I'm just curious of the math behind it, and since I've always programmed in assembly language on the old home computers of the 80's and 90's, I want to finally get back to it.
DrVeryEvil
Vic 20 Amateur
Posts: 69
Joined: Thu Jul 23, 2015 5:11 pm
Location: Lansing, MI, USA
Occupation: Data Analyst

Re: C=Hacking Issue #8

Post by DrVeryEvil »

On the first two equations, I was able to reduce them down to:
A. (cos(z-y)+cos(z+y))/2 B. (sin(z+y)+sin(z-y))/2

In the article they come up with t1=sy-sz and t2=sy+sz, yet the above that I came up with t1=sz-sy and t2=sz+sy. Did I do something wrong? How did they come up with that? Do I just turn them around? Did they use cos(y)cos(z) instead of cos(z)cos(y)? Are they both correct, because the operation is commutative?
Post Reply