PDA

View Full Version : Create a triangle of desidered pixel area


enigma
12-02-2008, 08:03 PM
Hi, I've a strange question.
Suppose that I setup the projection matrix with this function:

glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

and suppose that my viewport dimension is 1280x800.
Is possible to create a triangle of area (in pixel) 2^n?
For example, if I would a triangle of area 2^11 = 2048 pixel, how I must set the vertices? Or if I would a triangle of area 2^12, 2^13?
Is possible?
Thanks.

Reedbeta
12-02-2008, 09:22 PM
Of course. Just decide on what shape of triangle you want, then remember your triangle area formula A = 1/2 * base * height, where base is one side of the triangle and height is measured along a line perpendicular to base.

For instance, if it's a right triangle, base and height could be the lengths of the two legs. Then, for instance, to make an area of 2048 pixels, you would need the legs to be each sqrt(2 * 2048) = 64 pixels.

Or, you could also make one leg be 128 and the other 32, or one 256 and the other 16, etc. The two legs just have to multiply to 2 * 2048.

enigma
12-03-2008, 03:55 AM
Of course. Just decide on what shape of triangle you want, then remember your triangle area formula A = 1/2 * base * height, where base is one side of the triangle and height is measured along a line perpendicular to base.

For instance, if it's a right triangle, base and height could be the lengths of the two legs. Then, for instance, to make an area of 2048 pixels, you would need the legs to be each sqrt(2 * 2048) = 64 pixels.

Yes it's clear, and yes I would a right triangle. But my doubt is another.
Ok, for example, I would a triangle of area 2048 pixels, so the legs must be sqrt(2 * 2048) = 64 pixels. How is the best way to find the legs length (in world uint)? For example if my viewport is 1024x1024. This is my doubt.
Thanks.

enigma
12-03-2008, 04:46 AM
Ok, I've tried this and it's runs:
If I would a triangle of area 512 pixels I says that the legs must be 32 pixels. So if my viewport is 1024x1024 I must do this:
1 - ((32 - 512) / 512) = 0.0625
I've tried to find the area, and is correct.
But in this manner I obtain a correct area only if my desidered area is a multiple of 2^n, where n is a odd number.
If n is a even number, the area isn't an integer value. It's true?
Thanks.

Reedbeta
12-03-2008, 09:30 AM
That's right, it will only be exact for odd powers of two.

enigma
12-05-2008, 04:29 AM
Ok, thanks for help!

Lost
12-06-2008, 04:28 PM
I think you can get this to work for any arbitrary triangle. Lengths of sides should not matter.

1. For any triangle, calculate its area.
2. Take ratio of desired area / trig area.
3. Scale trig's vertices by above ratio. Trig area should now match desired area.

Reedbeta
12-06-2008, 05:27 PM
What do you mean by "trig area"? I've never heard that term before.

Lost
12-06-2008, 11:32 PM
trig = trigonometric = triangle
just an abbreviation.

I think it should work. Let me know if it doesn't.

And not just triangles. I think any 2D shape should work.