| Reference | Downloads | Github

Class visual.Triangle


Hi there,

I experienced a disadvantage using visual.Polygon for creating triangles. I like the basic idea that this class is based on vertices on the circumcircle and therefore only has a radius parameter for depicting its size. For an uneven number of vertices, however, the center of the shape is different from (i.e., higher than) the center of its circumcircle. Consequently, it seems to be displaced compared to other shapes such as visual.Rect and it also seems to have a smaller size than a visual.Circle of the same radius (since the latter is its circumcircle).

I, therefore, suggest to create a class visual.Triangle as a subclass of visual.ShapeStim that makes it easier to create triangles of given side length and/or height.

For an equilateral triangle of given height, here is a function I wrote for my purposes:
def Triangle(window, height=1): sideHalf = 0.577350269 #hard coded 1/math.sqrt(3) return visual.ShapeStim(win=window, vertices=((-sideHalf, -0.5), (0, 0.5), (sideHalf, -0.5)), size=height)



Does sound fair enough, especially since we have a rect and circle already as special instances of the shape

1 Like

Great! If you need any assistance with convenience functions like the one above let me know!