[Qt-interest] QPainter scale and rotate issue
Sean Harmer
sean.harmer at maps-technology.com
Thu Sep 2 10:17:56 CEST 2010
Hi,
On Thursday 02 September 2010 02:42:59 Yawar Amin wrote:
> Hi,
>
> I'm trying to teach myself simple QPainter usage and I have a
> QWidget-derived class as per attachments. I'm capturing the paint event
> and trying to draw a Pythagorean tree [1] using a 3-4-5 right triangle as
> the basis, with the following steps:
>
> 1. Draw the square with the 5 side, i.e. the one that corresponds to the
> hypotenuse, scaled up to 100 units. Draw from the top-left corner of the
> square and place the square at the bottom of the widget area.
>
> 2. Rotate the painter by -120, scale up to 80 units, and draw the square
> corresponding to the 4 side.
>
> 3. Translate the painter to the top right corner of the square, rotate by
> -120, scale up to 60 units, and draw the square corresponding to the 3
> side.
>
> Now according to Pythagoras, the three squares should meet to form a right
> triangle. But the top two triangles end up never meeting, no matter how
> much I tweak the rotating and scaling.
>
> Probably I'm doing something glaringly wrong? Can anyone comment?
If you are using a 3-4-5 triangle as the basic shape then it is your
trigonometry that is wrong. The internal angles are:
theta = asin( 4 / 5 ) = 53.13 degrees
phi = asin( 3 / 5 ) = 36.87 degrees
and the right-angle of course. So using rotations of 120 degrees both time
will just not work. Try it using these angles.
Cheers,
Sean
More information about the Qt-interest-old
mailing list