Computer Science Canada

Rotate Around a Point

Author:  Expirant [ Sat Oct 28, 2006 10:37 pm ]
Post subject:  Rotate Around a Point

I've been trying to figure this out, but I'm having a lot more trouble using sind and cosd on the computer than I do on paper. I need the image I've drawn with the procedure "DrawSoldier" to rotate around the soldier's head (The red circle). I know it's small, but there's a reason. Could someone possibly help out? I know there are a lot of variables, I just made this very quick tonight and I work in simple terms when trying to figure something out.

I'll paste my code below this, and if someone could alter it to the desired effect that'd be awesome. Thanks.

code:

var hx, hy, rax1, ray1, rax2, ray2, lax1, lay1, lax2, lay2, gx1, gx2, gy1, gy2 : int
hx := 100 % Head x coord
hy := 100 % Head y coord
rax1 := hx + 7 % Right arm x1
rax2 := hx % Right arm x2
ray1 := hy % Right arm y1
ray2 := hy - 5 %etc...
lax1 := hx - 7
lax2 := hx
lay1 := hy
lay2 := hy - 5
gx1 := hx - 2
gx2 := gx1
gy1 := lay2
gy2 := gy1 - 3

procedure DrawSoldier
    Draw.Line (hx - 2, hy, hx - 5, hy, cyan) %Right shoulder
    Draw.Line (hx + 2, hy, hx + 5, hy, cyan) %Left shoulder
    Draw.Line (rax1, ray1, rax2, ray2, black) %Right arm
    Draw.Line (lax1, lay1, lax2, lay2, black) %Left arm
    Draw.Line (gx1, gy1, gx2, gy2, black) %Gun
    Draw.FillOval (hx, hy, 3, 3, red) %Head
end DrawSoldier

DrawSoldier


Give the arms and head and shoulders and gun whatever coordinates you want, so long as the soldier is that big. I just had all those variables to make everything relative to the head, to make rotating the entire thing easier if I did indeed find out how.

(Or make a completely new thing, so long as it demonstrates your point!)

Thank ya,
Expirant

Author:  zylum [ Sat Oct 28, 2006 11:24 pm ]
Post subject: 

maybe this will help:

http://compsci.ca/v2/viewtopic.php?t=13866

Author:  Expirant [ Sun Oct 29, 2006 9:36 am ]
Post subject: 

Thank Zylum, I'll look into that. I found a better tutorial though on how to rotate pictures properly (I couldn't do it before...yikes). Anyways, The tutorial by AsianSensation was really well done. Thanks again.


AsianSensation tutorial on making a picture move in the direction it' facing:
http://www.compsci.ca/v2/viewtopic.php?t=3542


: