How can I create a triangle shape from the lenght of its sides?

Hello everyone

I would like to know if there is a way Dynamo can create a triangle from the lenght of its sides. If I have in data three numbers: 3,4,5, for example, can I draw a pythagorean triangle shape in a Dynamo model?

I’ve looking at this Python forum and an user asked how to create a triangle:

from turtle import color, begin_fill, forward, left, end_fill, done
from math import acos, degrees

def triangle_exists(a, b, c):
    """Return True iff there exists a triangle with sides a, b, c."""
    return a + b > c and b + c > a and c + a > b

def triangle_angle(a, b, c):
    """Return the angle (in degrees) opposite the side of length a in the
    triangle with sides a, b, c."""
    # See
    return degrees(acos((b ** 2 + c ** 2 - a ** 2) / (2.0 * b * c)))

def draw_triangle(a, b, c):
    """Draw a triangle with sides of lengths a, b, and c."""
    assert(triangle_exists(a, b, c))
    color('black', 'yellow')
    left(180 - triangle_angle(b, c, a))
    left(180 - triangle_angle(c, a, b))

>>> draw_triangle(400, 350, 200)

This is the code presented in the page I linked.

I would like to know if Dynamo can create geometries for triangles from code or if there exist nodes that help to do this.

Thanks in advance

If your triangle is Pythagorean you would only need the two sides to the right angle, as the hypotenuse is determined by these.

Computationally, this would look a bit like below.

Can I extend that script to scalene triangles? Or, if we went beyond, to lists of scalene triangles? I mean non pythagorean triangles too.

Yes but you would need to specify the angle between the two specified sides, that would be a bit different;

1 Like

Thanks a lot. I will try that method for lists of triangles according their lenght. I thought there could be a simpler method, less steps and nodes, I mean, but, for now, yours is useful for me.

1 Like

It could be broken down into design script or Python potentially, but it would be important to first focus on what the goal really is. A triangle floating in space in Dynamo doesn’t really achieve anything that can be applied outside this environment.

1 Like

I’m trying to build diagonalized polygons. The user draws the structure of a polygon without caring the distance and angle in CAD, based on the measures of an architectonic space. Then, according the structure of lines of the polygon, the user assigns lenghts for each line.
I’ve learnt that programmation requires a high patience to understand problems.

I would suggest looking into tesselation in the Lunchbox package, this has triangular divisions for surfaces (which polygons can generate);

1 Like

Lots of thanks. As I’m learning, LunchBox will be a great challenge and very useful for me.

1 Like