I've never used the GRAPHICS commands before, and this week while down with a bad cold, I started to learn some of them. One of the things I started with was:
but I was having trouble getting the triangle to paint, and not the space around it...
My estimates for x and y were often incorrect. I needed to find a way to be absolutely sure of a point inside the shape.
I did a LOT of research, reading, and test coding, and tried at least three methods. I settled on one that's straightforward and easily handles anything I could throw at it.
I'm posting it here as my way of saying thank you to all who have helped me in the past, in the hope that it might be of some small help.
After I do some more cleanup, I'll post the entire test program. It does have some pretty cool routines...
-John
Here's the change:
And here's the function; works like a champ with triangles of ANY shape:
Supporting TYPES:
Code:
GRAPHIC ATTACH hTriangle, 0 GRAPHIC POLYGON PlotPoints, %BLUE GRAPHIC PAINT (x, y) , %BLUE
My estimates for x and y were often incorrect. I needed to find a way to be absolutely sure of a point inside the shape.
I did a LOT of research, reading, and test coding, and tried at least three methods. I settled on one that's straightforward and easily handles anything I could throw at it.
I'm posting it here as my way of saying thank you to all who have helped me in the past, in the hope that it might be of some small help.
After I do some more cleanup, I'll post the entire test program. It does have some pretty cool routines...
-John
Here's the change:
Code:
GRAPHIC ATTACH hTriangle, 0 GRAPHIC POLYGON PlotPoints, %BLUE lRet = FindPointInTriangle (PlotPoints, StartPoint) GRAPHIC PAINT (StartPoint.x, StartPoint.y) , %BLUE
Code:
FUNCTION FindPointInTriangle (BYREF PointsList AS PolyArray, BYREF RetVal AS PolyPoint) AS LONG 'A known point inside a triangle is it's "centroid", where the medians of the angles intersect RetVal.x = (PointsList.xy(1).x + PointsList.xy(2).x + PointsList.xy(3).x) / 3 RetVal.y = (PointsList.xy(1).y + PointsList.xy(2).y + PointsList.xy(3).y) / 3 FUNCTION = %TRUE END FUNCTION
Supporting TYPES:
Code:
TYPE PolyPoint x AS SINGLE y AS SINGLE END TYPE TYPE StraightLine p1 AS PolyPoint 'some point that is on the line p2 AS PolyPoint 'some other point that is on the line SegLen AS SINGLE 'optional Rise AS SINGLE 'optional Run AS SINGLE 'optional Slope AS SINGLE 'optional END TYPE TYPE PolyArray COUNT AS LONG xy(1 TO 100) AS PolyPoint 'Can't redim dynamically, but extras aren't harmful END TYPE TYPE Triangle Points AS PolyArray ' TriangleName.Points.xy(1).x S12 AS StraightLine 'Side S23 AS StraightLine 'Side S13 AS StraightLine 'Side A12 AS SINGLE 'Angle A23 AS SINGLE 'Angle A13 AS SINGLE 'Angle Centroid AS PolyPoint'intersection of medians TriangleClassA AS STRING * 7 'Classifcation based on Angles (eg, right, obtuse, acute) TriangleClassS AS STRING * 11 'Classifcation based on Sides (equilateral, scalene, isoceles) ' lengths accomodate full text descriptors ' (if we stored only the first char, we'd need programatic interpretations later) END TYPE
Comment