Author Topic: Rotation- How does it work??  (Read 12600 times)

0 Members and 1 Guest are viewing this topic.

Offline nxtboy III

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 795
  • Rating: +26/-1
  • NXT!
    • View Profile
    • Program NXT
Re: Rotation- How does it work??
« Reply #30 on: March 13, 2012, 05:27:48 pm »
How would I use fixed-point? Doesn't it have to be floating-point??

Could you explain "shearing" to me?

EDIT: But it involves skewing! How would I do that??
« Last Edit: March 13, 2012, 05:32:09 pm by nxtboy III »

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
Re: Rotation- How does it work??
« Reply #31 on: March 13, 2012, 08:29:10 pm »
How would I use fixed-point? Doesn't it have to be floating-point??
Fixed-point is just using values multiplied by a scaling factor, usually a power of two for efficiency. Say you have a 16-bit integer and you split it into 8 bits for the integer part and 8 bits for the fractional part. That's the same as multiplying a real (floating-point) number by 256 and then taking the integer portion. Then to add two fixed-point numbers, just add them as usual. To multiply two numbers, multiply them as usual and then divide by 256. To divide, multiply the numerator by 256 and then divide by the denominator. Since you probably won't want to write your own cosine and sine functions, you can still use the same ones after converting the fixed-point number back to floating point (cast it to float and divide by 256).

Of course, you can use more than 8 bits for the integer and fraction parts, and they don't have to be the same. How many bits you use depends on the range and precision you need and the size of the available integer types (16 and 32 being the most common).

Quote
Could you explain "shearing" to me?

EDIT: But it involves skewing! How would I do that??
Shearing is basically like taking a rectangle and moving the top and bottom in opposite directions so that you end up with a parallelogram. The top and bottom are the same length, and the parallelogram has the same height as the original rectangle, but the sides are longer than the original.

Here's a little illustration showing a rectangle getting x-sheared:
Code: [Select]
original:
  xxxxxx
  xxxxxx
  xxxxxx
  xxxxxx

x-sheared (alpha=-1):
xxxxxx
 xxxxxx
  xxxxxx
   xxxxxx
Y-shearing is the same but along the y axis. I can't help with an implementation for several reasons, such as that I don't even know what pixel format it uses. Besides, that link I gave you has an implementation in a Pascal-like language and one in Matlab.
Christopher Williams

Offline nxtboy III

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 795
  • Rating: +26/-1
  • NXT!
    • View Profile
    • Program NXT
Re: Rotation- How does it work??
« Reply #32 on: March 13, 2012, 08:41:15 pm »
Do you think you could show some code for all the fixed/floating point stuff?

EDIT: BuilderBoy- Just to tell you, NXC (Language I use for my NXT) has some stuff that you can do in Axe/BASIC/Grammer, like checking if a pixel is on or off.
« Last Edit: March 13, 2012, 09:58:13 pm by nxtboy III »