[1]:
from manim import *
from manim_geometry import *
config.media_embed = True
config.media_width = "100%"
_RV = "-v WARNING -qm --progress_bar None --disable_caching"
_RI = "-v WARNING -s --progress_bar None --disable_caching"
Manim Community v0.18.0
17-sided polygon¶
I used this video as a reference:
[2]:
FRAME_HEIGHT = config.frame_height
FRAME_WIDTH = config.frame_width
class Polygon17Sides(Scene):
def fade_out(self, *mobs, **kwargs):
self.play(
*map(FadeOut, mobs),
**kwargs
)
def construct(self):
geos = Geos(self)
frame_y_radius = FRAME_HEIGHT/2
frame_x_radius = FRAME_WIDTH/2
ac = lambda color: {
"all_styles": {"color": color},
}
geos.create_geos({
"lY": geos.line(DOWN*frame_y_radius, UP*frame_y_radius),
"lX": geos.line(LEFT*frame_x_radius, RIGHT*frame_x_radius),
"cO": geos.circle(ORIGIN, 3.5, line_kwargs={"color": RED}),
"dO1": geos.dot_from_method(lambda n: n("cO").get_top()),
"lO1": geos.common_chord_partial("dO1", "cO", **ac(GREEN)),
"dO2": geos.intersection_lines("lO1", "lY"),
"lO2": geos.line_bisection_two_points("dO2", ORIGIN, **ac(GREEN)),
"dA": geos.intersection_lines("lO2", "lY"),
"dB": geos.dot_from_method(lambda n: n("cO").get_right()),
"lAB": geos.segment("dA,dB"),
"aO": geos.arc_three_points("dB,dA,dO1", 2.3, other_angle=True),
"dC": geos.nearest_intersection_circle_line("aO", "lAB", "dB"),
"dD": geos.nearest_intersection_circle_line("aO", "lY", ORIGIN),
"dE": geos.farthest_angle_bisector("dC", "dD", ORIGIN),
"lAE": geos.line("dA", "dE"),
"dF": geos.nearest_intersection_circle_line("aO", "lAE", ORIGIN),
"dG": geos.farthest_angle_bisector("dF", "dD", ORIGIN),
"lGA": geos.line("dG", "dA", overshot=2.5),
# ----
"dH,dI": geos.intersection_circle_line("aO", "lGA"),
"dJ": geos.farthest_angle_bisector("dH", "dI", "dO1", **ac(BLUE)),
"lAJ": geos.line("dA", "dJ"),
"dK": geos.nearest_intersection_circle_line("aO", "lAJ", "dJ"),
"dL": geos.farthest_angle_bisector("dK", "dI", ORIGIN, **ac(BLUE)),
"lAL": geos.line("dA", "dL"),
"dM": geos.intersection_lines("lX", "lGA"),
"dN": geos.intersection_lines("lX", "lAL"),
"lBN": geos.line_bisection_two_points("dB", "dN", **ac(GREEN)),
"dP": geos.intersection_lines("lX", "lBN"),
"nPN": geos.distance("dN", "dP"),
"aP": geos.arc("dP", "nPN", PI, -60*DEGREES, **ac(BLUE)),
"dQ": geos.nearest_intersection_circle_line("aP", "lY", "dA"),
"nMQ": geos.distance("dM", "dQ"),
"aM": geos.arc_three_points(
"dP,dM,dQ", radius="nMQ", overshot_ang=0, reverse_points=True,
**ac(GREEN),
),
"dR": geos.nearest_intersection_circle_line("aM", "lX", "dP"),
"cR": geos.circle("dR", 0.8, **ac(GREEN)),
"dS,dT": geos.intersection_circle_line("cR", "lX"),
"dU": geos.nearest_angle_bisector("dS", "dT", "dA", **ac(BLUE)),
"lRU": geos.line("dR","dU", overshot=2.3),
"dW": geos.nearest_intersection_circle_line("cO", "lRU", "dU"),
"lEND": geos.line("dB", "dW", color=RED),
},
)
self.add(geos.lX, geos.lY)
geos.auto_animation("cO")
geos.auto_animation("lO1", remove_arc=False)
geos.auto_animation("lO2", remove_arcs=False)
geos.auto_animation("lAB")
self.play(
*map(FadeOut, [geos.lO1, geos.lO1.arc, geos.lO2, geos.lO2.arcs])
)
geos.auto_animation("aO")
geos.auto_animation("dE", remove_arcs=False)
geos.auto_animation("lAE")
geos.auto_animation("dG", remove_arcs=False)
geos.auto_animation("lGA", show_dots=False)
geos.auto_animation("dJ", remove_arcs=False)
self.fade_out(
geos.dE.arcs, geos.dG.arcs, geos.lAE
)
geos.auto_animation("lAJ")
geos.auto_animation("dL", remove_arcs=False)
geos.auto_animation("lAL")
self.fade_out(
geos.dL.arcs, geos.lAJ,
geos.dJ.arcs, geos.aO, geos.lAB
)
geos.auto_animation("lBN", remove_arcs=False)
geos.auto_animation("aP")
self.fade_out(
geos.lBN.arcs, geos.lBN
)
geos.auto_animation("aM")
geos.auto_animation("cR")
geos.auto_animation("dU", remove_arcs=False)
geos.auto_animation("lRU", show_dots=False)
geos.auto_animation("lEND")
self.fade_out(
geos.lGA, geos.lAL, geos.aP, geos.aM,
geos.lRU, geos.dU.arcs, geos.cR
)
rotate_line = geos.lEND
main_circle = geos.cO
pol17 = RegularPolygon(
17,
radius=geos.cO.radius,
start_angle=0,
color=YELLOW,
stroke_width=2
).move_to(geos.cO)
arcs = VGroup()
for _ in range(17):
tmp_circle = ICircle(rotate_line.get_length()).move_to(rotate_line.get_end())
arc = tmp_circle.common_chord_group_partial(main_circle, only_arc=True)
arc.reverse_points()
arc.set_stroke(width=3)
arcs.add(arc)
self.play(
Rotate(rotate_line, -arc.angle, about_point=rotate_line.get_end()),
Create(arc),
)
rotate_line.reverse_points()
self.play(FadeOut(rotate_line))
self.play(Create(pol17))
self.wait()
self.fade_out(main_circle, arcs, geos.lX, geos.lY)
pol17_labels = RegularPolygon(
17, radius=geos.cO.radius*0.9,
start_angle=0
)
pol17_labels_anchors = pol17_labels.get_anchors()
labels = VGroup(*[
MathTex(str(i+1)).scale(0.5).move_to(pol17_labels_anchors[i*2])
for i in range(17)
])
self.play(LaggedStartMap(FadeIn, labels))
self.wait(4)
%manim $_RV Polygon17Sides
[ ]: