Oh, trigonometry~

Get help using Construct 2

Post » Wed Feb 22, 2012 5:17 am

I never figured out trigonometry enough to solve this little problem I have.

As you may know, when a layer rotates in construct, it rotates with its axis included, so the coordinates move with it, something like this:





Now, I need a formula that, knowing the angle of rotation of the layer, tells me the visual position of a point (in the example, I would want (0,y) instead of (x,y)).

Any help would be greatly appreciated n__n!

Edit: note that the point can move freely. So I need to know the absolute position of the point of its relative position in the rotated layer.kirby2012-02-22 05:44:49
B
22
S
3
G
6
Posts: 59
Reputation: 4,450

Post » Wed Feb 22, 2012 12:52 pm

cx,cy are the coordinates of the center of rotation
xR,yR are the coordinates in a rotated layer at angle layerangle
x,y are the coordinates in an unrotated layer

x = cx + cos(-layerangle) * distance(cx,cy,xR,yR)
y = cy + sin(-layerangle) * distance(cx,cy,xR,yR)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Feb 22, 2012 7:45 pm

It doesn't work because if the layer is not rotated (i.e. layerangle = 0), its sine = 0, so y = cy.

:<
B
22
S
3
G
6
Posts: 59
Reputation: 4,450

Post » Wed Feb 22, 2012 7:46 pm

yeah your right

x = cx + cos(-layerangle+angle(cx,cy,xR,yR)) * distance(cx,cy,xR,yR)
y = cy + sin(-layerangle+angle(cx,cy,xR,yR)) * distance(cx,cy,xR,yR)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Feb 22, 2012 9:59 pm

Thank you very much! It works now!

You'll be in the credits of every game for the contest, it appears xD
B
22
S
3
G
6
Posts: 59
Reputation: 4,450


Return to How do I....?

Who is online

Users browsing this forum: DiabloOvermind, MrWhizm, Skebab, spcsmrf and 20 guests