Page 1 of 1
how to make fit...
Posted: Sat Jan 26, 2013 5:17 pm
by tester
How to make that vector triangle fit the whole square/rectangle? (non-ruby)
Re: how to make fit...
Posted: Sun Jan 27, 2013 1:23 pm
by trogluddite
The triangle in the example is drawn by using a single very thick line that is angled at 45deg. This effectively gives you a rectangle (line length * line width) rotated to 45deg. The triangle is then one corner of this rectangle clipped off by the view area - which mean that the angle at the lower point has to be 90deg.
To change the height of the triangle would require that angle to be different, and so it cannot be done using this method.
Three possible solutions...
1) Masking
For this technique you would have to have a GUI with a definite background colour - and then use other rotated rectangles (i.e. wide lines) drawn in the background colour to 'paint out' areas of pixels that are not part of the shape. But this will lead to some fiendishly complex maths - the required geometry would change, for example, as the triangle's apex changed from an acute to obtuse angle.
2) Fill your own shape.
Using geometry and draw loops, you would 'scan' the shape, using the equations of it's geometry to define lines of pixels that needed filling, building up the shape a row at a time. For this shape, a simple 'fan' might be easiest - scan along the top edge one pixel at a time, drawing a line from there to the triangle's apex.
A search for 'polygons' on the SM site should find you a few good examples - I remember there being a few threads about creating filled shapes.
3) Use Ruby to just draw the outline and let GDI+ do all the hard work.
I know, you said a 'non-Ruby' solution, but for non-trivial shapes, the old 'green/yellow' vector primitives are, well, just a bit too 'primitive' - there is no way to define 'fillable' outlines with them other than the default rectangle and ellipse shapes (and the "thick lines" method for rotated rectangles). OTOH with Ruby you can easily fill very complex outlines, including those with combinations of straight and curved edges - this is one area where Ruby really does have a huge advantage over the old methods.
Re: how to make fit...
Posted: Sun Jan 27, 2013 1:49 pm
by tester
Thanks for explaining.
Meanwhile I just resigned somewhat from triangular pointers - the simplest way

Right now I'm avoiding ruby for a moment. My lack of knowledge/experience on that, this "roaming folder" thing and uncertainty to the performance of ruby-driven modules - makes me to wait with that.