
-----------------------------------
riveryu
Wed May 14, 2008 6:36 pm

Pic.Rotate cut off pics
-----------------------------------
How do I avoid cutting off parts of a picture when rotating a picture at a certain point?

-----------------------------------
Sean
Wed May 14, 2008 6:43 pm

Re: Pic.Rotate cut off pics
-----------------------------------
Can you give us the code that had this error in it, so we can see what is wrong. Hard to tell when we don't see exactly what you see.

-----------------------------------
isaiahk9
Wed May 14, 2008 6:48 pm

RE:Pic.Rotate cut off pics
-----------------------------------
an inefficient way (but easy) would to just add more white around the edges of the picture, so that only white is cut off and we don't see it

-----------------------------------
riveryu
Wed May 14, 2008 6:50 pm

Re: Pic.Rotate cut off pics
-----------------------------------
Here is an example of the situation, maybe im using Pic.Rotate wrongly...
View.Set ("graphics:1000;600,offscreenonly")
var picID:int
var picID1 :int
drawfillbox (100,100,200,200,red)
picID:=Pic.New(100,100,200,200)
for i:1..360
picID1:=Pic.Rotate(picID,i,100,100)
Pic.Draw(picID1,100,100,0)
delay(50)
View.Update
cls
end for


-----------------------------------
riveryu
Wed May 14, 2008 7:21 pm

RE:Pic.Rotate cut off pics
-----------------------------------
Thanks isaiahk9, that solved the problem.

Aside from that,is there an actual "efficient" way? Anyone?

-----------------------------------
Tony
Wed May 14, 2008 7:45 pm

RE:Pic.Rotate cut off pics
-----------------------------------
Writing your own function would be the way to go for this one. Rotate just the non-white pixels for optimization. You could make it super fast if you pre-calculate some transformation matrices. Keeping equations more abstract requires more calculations run-time, but allows for greater flexibility.

This is how most of 2D graphics are handled -- [url=http://en.wikipedia.org/wiki/Transformation_matrix#Examples_in_2D_graphics]rotation, scaling, shearing, reflections, projection

-----------------------------------
Saad
Wed May 14, 2008 7:53 pm

Re: RE:Pic.Rotate cut off pics
-----------------------------------
Thanks isaiahk9, that solved the problem.

Aside from that,is there an actual "efficient" way? Anyone?

A much better way would be to use 2D rotation.

The 2D rotation formula is the following

(TeX tags for the win)

This however works only for the origin, and as a result you want to tranlate it to the origin.

Some code that you might want to look at


const AMOUNT_TO_ROTATE := 1
const NUMBER_OF_ROTATIONS := 360
const CENTER_X := 250
const CENTER_Y := 250
var x : real := 100
var y : real := 0
x += CENTER_X
y += CENTER_Y

for rotationIndex : 1 .. NUMBER_OF_ROTATIONS
    x -= CENTER_X %% Move the point to the center
    y -= CENTER_Y
    %% Plug into the rotation formula
    %% We will save them into new variables as we need to use to original x and y
    var newX := x * cosd (AMOUNT_TO_ROTATE) - y * sind (AMOUNT_TO_ROTATE)
    var newY := y * cosd (AMOUNT_TO_ROTATE) + x * sind (AMOUNT_TO_ROTATE)
    
    x := newX
    y := newY

    x += CENTER_X  %% Move the point back away from the center
    y += CENTER_Y
    Draw.FillOval (round (x), round (y), 10, 10, black)
    Time.Delay (10)
end for


Now apply the rotation too all the points on the square

-----------------------------------
riveryu
Wed May 14, 2008 8:07 pm

RE:Pic.Rotate cut off pics
-----------------------------------
Thanks a lot! Tony, Saad. When did you guys learn about transformation matrices? I wish I'll learn it in grade 10...Do you learn this in math courses? I dont like using something I dont understand...

I wish there is a list of topics for people to learn about from beginner to advanced just from programming theories(concepts thats feasible no matter the language).

Does such a list already exist? I would gladly make one for ppl if I know enough.

-----------------------------------
syntax_error
Wed May 14, 2008 11:56 pm

RE:Pic.Rotate cut off pics
-----------------------------------
you dont need a math course per se, to learn them, if you have an interest: library. enough said.

-----------------------------------
CodeMonkey2000
Thu May 15, 2008 2:59 pm

RE:Pic.Rotate cut off pics
-----------------------------------
Better yet, internet. Don't limit your education to just what you do in school.
