Triangle Related Definitions
Equilateral Triangles
PlaneGeometry.isequilateral
โ Functionisequilateral(๐๏ธ)
Check if ๐๏ธ
is equilateral, i.e., if the three edges of ๐๏ธ
are of the same length.
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
PlaneGeometry.equipoints
โ Functionequipoints(A, B)
Find the two points the can form an equilateral triangle with A
and B
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
PlaneGeometry.outer_equitri
โ Functionouter_equitri(A, B, C)
Find the outer equilateral triangle of Triangle(A, B, C)
which is incident to Edge(A, B)
.
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
PlaneGeometry.outer_equitriangles
โ Functionouter_equitriangles(๐๏ธ)
Find all three outer equilateral triangles of the triangle ๐๏ธ
.
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
PlaneGeometry.median
โ Functionmedian(A::Point, B::Point, C::Point)
Find the edge from the midpoint of A
and B
to C
.
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)