ruby-gnome2 question

J

Joe Van Dyk

I have a GnomeCanvas Group that I'm trying to rotate (in 2D).

I know which direction the "top" of the group should be pointing.

My initial attempt was
affine = Art::Affine.new([Math.cos(180), -Math.sin(180), 0,
Math.sin(180), Math.cos(180), 0])
@group.affine_absolute(affine)

That was to rotate the object 180 degrees, but it didn't work too
well. I'm pretty new to all this matrix transformation / graphical
stuff. Could someone tell me if I'm on the right track?

Thanks,
Joe Van Dyk
 
J

Joe Van Dyk

I have a GnomeCanvas Group that I'm trying to rotate (in 2D).

I know which direction the "top" of the group should be pointing.

My initial attempt was
affine = Art::Affine.new([Math.cos(180), -Math.sin(180), 0,
Math.sin(180), Math.cos(180), 0])
@group.affine_absolute(affine)

That was to rotate the object 180 degrees, but it didn't work too
well. I'm pretty new to all this matrix transformation / graphical
stuff. Could someone tell me if I'm on the right track?

Nevermind, I got it. Reading through the C LibArt documentation, the
affine matrix needs to be in (x1, y1, x2, y2, x3, y3) format, not (x1,
x2, x3, y1, y2, y3) as I assume.
 
J

Joe Van Dyk

I have a GnomeCanvas Group that I'm trying to rotate (in 2D).

I know which direction the "top" of the group should be pointing.

My initial attempt was
affine = Art::Affine.new([Math.cos(180), -Math.sin(180), 0,
Math.sin(180), Math.cos(180), 0])
@group.affine_absolute(affine)

That was to rotate the object 180 degrees, but it didn't work too
well. I'm pretty new to all this matrix transformation / graphical
stuff. Could someone tell me if I'm on the right track?

Nevermind, I got it. Reading through the C LibArt documentation, the
affine matrix needs to be in (x1, y1, x2, y2, x3, y3) format, not (x1,
x2, x3, y1, y2, y3) as I assume.

Well, I thought I had it.

I have an Gnome::CanvasItem that's, say, at position (100, 100). When
I attempt to use a rotation affine translation, it rotates and moves
the object to some other place.

All I want to do is be able to rotate the item by a certain amount of
degrees in 2D space and have it stay at the same x/y coordinate.

Any ideas?
 
M

Martin DeMello

Joe Van Dyk said:
All I want to do is be able to rotate the item by a certain amount of
degrees in 2D space and have it stay at the same x/y coordinate.

Any ideas?

Not familiar with the gnome api, but in general you need to translate
the object so that the rotation point is on the origin, apply the
rotation matrix, and then translate it back.

martin
 
J

Joe Van Dyk

Not familiar with the gnome api, but in general you need to translate
the object so that the rotation point is on the origin, apply the
rotation matrix, and then translate it back.

martin

Ah.... the origin of the object?
 
M

Martin DeMello

Joe Van Dyk said:
Ah.... the origin of the object?

No, the origin of your coordinate system. For instance, let your object
be at (100,100) and say you want to rotate it around the point
(100,100). Then the first thing you need to do is translate the rotation
point to 0,0, which means translating the object by -100, -100. Then
rotate, then translate back. So the operation is

final = T(100,100) R(theta) T(-100, -100) original

since matrix multiplication goes from right to left. Or, in function
form

T1 = art_affine_translate(-100, -100)
T2 = art_affine_translate(100, 100)
R = art_affine_rotate(theta)

final = T2*(R*(T1*original))

http://www.cs.wpi.edu/~emmanuel/courses/cs4731/slides/lecture09.pdf
looks like a nice reference.

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top