Triangle Related Definitions

    Equilateral Triangles

    PlaneGeometry.isequilateral โ€” Function
    isequilateral(๐Ÿ“๏ธ)

    Check if ๐Ÿ“๏ธ is equilateral, i.e., if the three edges of ๐Ÿ“๏ธ are of the same length.

    source

    Source Code

    function isequilateral(๐Ÿ“๏ธ)
        dist = [squaredist(e.src, e.dst) for e in edges(๐Ÿ“๏ธ)]
        if (dist[1] == dist[2]) && (dist[1] == dist[3])
            return true
        else
            return false
        end
    end

    Equilateral Points

    Source Code

    function equipoints(A, B)
        x, y = @vars x y
        pt = Point(x, y)
        dist1 = squaredist(pt, A)
        dist2 = squaredist(pt, B)
        dist3 = squaredist(A, B)
        sol = solve([dist1-dist3, dist2-dist3], [x,y])
        [Point(simplify(s[1]), simplify(s[2])) for s in sol]
    end

    Picture

    A = Point(0,0); B = Point(1, 3); C = Point(4,2)
    ptAB = equipoints(A, B)
    scatter(shape([A, B]), leg=false, color=:red,
        series_annotations = text.(["A", "B"], :bottom))
    scatter!(shape(ptAB), leg=false, color=:green,
        series_annotations = text.(["1", "2"], :bottom))
    [plot!(Triangle(A, B, pt), leg=false, fill=(0, :pink),
        aspect_ratio=:equal, fillalpha= 0.7) for pt in ptAB]
    current()

    Outer Equilateral Triangle

    Source Code

    function outer_equitri(A, B, C)
        ptAB = equipoints(A, B)
        dist = map(pt->squaredist(pt, C), ptAB)
        d = simplify(dist[1]-dist[2])
        if simplify(d>=0)
            return Triangle(A, B, ptAB[1])
        else
            return Triangle(A, B, ptAB[2])
        end
    end

    Picture

    tri = Triangle(A, B, C)
    tri_out = outer_equitri(A, B, C)
    scatter(shape([A, B, C]), leg=false, color=:red,
        series_annotations = text.(["A", "B", "C"], :bottom))
    plot!(tri_out, leg=false, fill=(0, :pink), aspect_ratio=:equal, fillalpha= 0.7)
    plot!(tri, fill=(0, :green), aspect_ratio=:equal, fillalpha= 0.2)

    All Three Outer Equilateral Triangles

    Source Code

    function outer_equitriangles(๐Ÿ“๏ธ)
        pts = vertices(๐Ÿ“๏ธ)
        triangles = map(i->outer_equitri(circshift(pts, i)...), 0:2)
        triangles
    end

    Picture

    tri_out = outer_equitriangles(tri)
    scatter(shape([A, B, C]), leg=false, color=:red,
        series_annotations = text.(["A", "B", "C"], :bottom))
    for t in tri_out
        plot!(t, leg=false, fill=(0, :pink), aspect_ratio=:equal, fillalpha= 0.7)
    end
    plot!(tri, fill=(0, :green), aspect_ratio=:equal, fillalpha= 0.2)

    Median

    Source Code

    function median(A::Point, B::Point, C::Point)
        Edge(midpoint(A, B), C)
    end

    Picture

    me = median(A, B, C)
    mid = midpoint(A, B)
    scatter(shape([A, B, C, mid]), leg=false, color=:red,
        series_annotations = text.(["A", "B", "C", "mid"], :bottom))
    plot!(me, color=:orange)
    plot!(tri, fill=(0, :green), aspect_ratio=:equal, fillalpha= 0.2)