trying-manim/constructions.py

456 lines
18 KiB
Python

#!/usr/bin/env python3
from manimlib.imports import *
from math import radians,sin,cos
class AngleBisector(Scene):
def construct(self):
ANGLE = math.radians(35)
mainTitle = TextMobject("Angle Bisector")
mainTitle.to_corner()
self.add(mainTitle)
cornerDot = Dot(2 * LEFT + 2 * DOWN, color=GREEN)
mainAngle1 = Line(start=2 * LEFT + 2 * DOWN, end=2 * DOWN + 3 * RIGHT, color=GREEN)
mainAngle2 = Line(start=2 * LEFT + 2 * DOWN, end=Common.polarToCartesian(5, ANGLE, 2 * LEFT + 2 * DOWN), color=GREEN)
self.play(ShowCreation(mainAngle1))
self.play(Transform(Line(start=2 * LEFT + 2 * DOWN, end=2 * DOWN + 3 * RIGHT, color=GREEN), mainAngle2))
mainAngle2.rotate(ANGLE)
self.wait(1)
cornerDot.set_color(RED)
arc1 = Arc(math.radians(50), math.radians(-60), radius=2)
arc1.shift(2 * LEFT + 2 * DOWN)
self.play(ShowCreation(arc1))
cornerDot.set_color(GREEN)
dot1 = Dot(point=2 * DOWN, color=BLUE)
dot2 = Dot(point=Common.polarToCartesian(2, ANGLE, center=2 * DOWN + 2 * LEFT), color=BLUE)
self.play(ShowCreation(dot1), ShowCreation(dot2))
self.wait(1)
dot1.set_color(RED)
dot2.set_color(RED)
arc2 = Arc(math.radians(180), math.radians(-180), arc_center=2 * DOWN)
arc3 = Arc(math.radians(215), math.radians(180), arc_center=Common.polarToCartesian(2, ANGLE, center=2 * DOWN + 2 * LEFT))
self.play(ShowCreation(arc2), ShowCreation(arc3))
dot1.set_color(BLUE)
dot2.set_color(BLUE)
self.wait(1)
bisector = Line(start=2 * LEFT + 2 * DOWN, end=Common.polarToCartesian(6, ANGLE / 2, 2 * LEFT + 2 * DOWN))
self.play(ShowCreation(bisector))
self.wait(1)
self.play(FadeOutAndShiftDown(arc1))
self.play(FadeOutAndShiftDown(dot1), FadeOutAndShiftDown(dot2))
self.play(FadeOutAndShiftDown(arc2), FadeOutAndShiftDown(arc3))
self.wait(3)
class ParallelLine(Scene):
def construct(self):
mainTitle = TextMobject("Parallel Line")
mainTitle.to_corner()
self.add(mainTitle)
mainDot = Dot(point=2 * DOWN, color=GREEN)
mainLine = Line(start=2 * LEFT, end=2 * RIGHT, color=GREEN)
self.play(ShowCreation(mainDot), ShowCreation(mainLine))
self.wait(1)
# Draw perpendicular bisector
## Draw equal distance points
mainDot.set_color(RED)
pointFindingArc = Arc(math.radians(30), math.radians(120), arc_center=2 * DOWN, radius=2.3)
self.play(ShowCreation(pointFindingArc))
mainDot.set_color(GREEN)
dot1 = Dot(Common.polarToCartesian(2.3, 1.054, 2 * DOWN), color=BLUE)
dot2 = Dot(Common.polarToCartesian(2.3, PI - 1.054, 2 * DOWN), color=BLUE)
self.play(ShowCreation(dot1), ShowCreation(dot2))
self.wait(1)
## Draw half circles
dot1.set_color(RED)
dot2.set_color(RED)
perpFindingArc1 = Arc(math.radians(50), math.radians(-100), radius=1.4, arc_center=Common.polarToCartesian(2.3, PI -1.054, 2 * DOWN))
perpFindingArc2 = Arc(math.radians(230), math.radians(-100), radius=1.4, arc_center=Common.polarToCartesian(2.3, 1.054, 2 * DOWN))
self.play(ShowCreation(perpFindingArc1), ShowCreation(perpFindingArc2))
dot1.set_color(BLUE)
dot2.set_color(BLUE)
self.wait(1)
## Draw Perpendicular line
perpendicularLine = Line(3 * DOWN, UP)
self.play(ShowCreation(perpendicularLine))
self.wait(1)
# Draw Parallel Line
## Find points on perpendicular line
mainDot.set_color(RED)
perpDistCircle = Circle(arc_center=2 * DOWN, radius=0.8)
self.play(ShowCreation(perpDistCircle))
mainDot.set_color(GREEN)
perpDistDot1 = Dot((2 - 0.8) * DOWN, color=BLUE)
perpDistDot2 = Dot((2 + 0.8) * DOWN, color=BLUE)
self.play(ShowCreation(perpDistDot1), ShowCreation(perpDistDot2))
self.wait(1)
## Find Parallel Line Arcs
perpDistDot1.set_color(RED)
perpDistDot2.set_color(RED)
paraFindingArc1 = Arc(math.radians(40), math.radians(100), arc_center=(2 + 0.8) * DOWN)
paraFindingArc2 = Arc(math.radians(220), math.radians(100), arc_center=(2 - 0.8) * DOWN)
self.play(ShowCreation(paraFindingArc1), ShowCreation(paraFindingArc2))
perpDistDot1.set_color(BLUE)
perpDistDot2.set_color(BLUE)
self.wait(1)
## Find Parallel Line
paralellLine = Line(2 * DOWN + 2 * LEFT, 2 * DOWN + 2 * RIGHT)
self.play(ShowCreation(paralellLine))
self.wait(2)
# Remove all construction materials
self.play(FadeOutAndShiftDown(pointFindingArc))
self.play(FadeOutAndShiftDown(dot1), FadeOutAndShiftDown(dot2))
self.play(FadeOutAndShiftDown(perpFindingArc1), FadeOutAndShiftDown(perpFindingArc2))
self.play(FadeOutAndShiftDown(perpendicularLine))
self.play(FadeOutAndShiftDown(perpDistCircle))
self.play(FadeOutAndShiftDown(perpDistDot1), FadeOutAndShiftDown(perpDistDot2))
self.play(FadeOutAndShiftDown(paraFindingArc1), FadeOutAndShiftDown(paraFindingArc2))
self.wait(3)
class PerpendicularBisector(Scene):
def construct(self):
DRAW_ANGLE = 40
mainTitle = TextMobject("Perpendicular Bisector")
mainTitle.to_corner()
self.add(mainTitle)
mainLine = Line(start=LEFT, end=RIGHT)
leftDot = Dot(LEFT, color=BLUE)
rightDot = Dot(RIGHT, color=BLUE)
self.play(ShowCreation(mainLine), ShowCreation(leftDot), ShowCreation(rightDot))
leftDot.set_color(RED)
arc1 = Arc(start_angle=math.radians(-DRAW_ANGLE), angle=math.radians(DRAW_ANGLE * 2), arc_center=LEFT, radius=1.2)
self.play(ShowCreation(arc1))
leftDot.set_color(BLUE)
rightDot.set_color(RED)
arc2 = Arc(start_angle=math.radians(DRAW_ANGLE - 180), angle=math.radians(-2 * DRAW_ANGLE), arc_center=RIGHT, radius=1.2)
self.play(ShowCreation(arc2))
rightDot.set_color(BLUE)
bisector = Line(start=3 * DOWN, end=3 * UP)
self.play(ShowCreation(bisector))
self.play(FadeOutAndShiftDown(arc1), FadeOutAndShiftDown(arc2))
lineLengthEqual1A = Line(start=0.1 * DOWN + 0.5 * RIGHT, end=0.1 * UP + 0.5 * RIGHT)
lineLengthEqual1B = Line(start=0.1 * DOWN + 0.5 * LEFT, end=0.1 * UP + 0.5 * LEFT)
self.play(ShowCreation(lineLengthEqual1A), ShowCreation(lineLengthEqual1B))
rightAngleTick1 = Group(Line(start=0.1 * UP, end=0.1 * UP + 0.1 * RIGHT), Line(start=0.1 * UP + 0.1 * RIGHT, end=0.1 * RIGHT))
self.play(ShowCreation(rightAngleTick1))
self.wait(3)
class PerpendicularPlane(ThreeDScene):
def construct(self):
WAIT = 1.5
mainTitle = TextMobject("Line to Perpendicular Plane")
mainTitle.to_corner()
self.add_fixed_in_frame_mobjects(mainTitle)
self.move_camera(0.8*np.pi/2, -0.45*np.pi)
self.begin_ambient_camera_rotation()
mainLine = Line(2 * LEFT, 2 * RIGHT, COLOR=GREEN)
self.play(ShowCreation(mainLine))
self.wait(WAIT)
centerDot = Dot(color=BLUE)
self.play(ShowCreation(centerDot))
centerDot.set_color(RED)
mainSphere = Sphere(fill_opacity=0.5, radius=0.75)
self.play(ShowCreation(mainSphere))
centerDot.set_color(BLUE)
leftDot = Dot(0.75 * LEFT, color=BLUE)
rightDot = Dot(0.75 * RIGHT, color=BLUE)
self.play(ShowCreation(leftDot), ShowCreation(rightDot))
leftDot.set_color(RED)
rightDot.set_color(RED)
sphere1 = Sphere(fill_opacity=0.5)
sphere1.shift(0.75 * LEFT)
sphere2 = Sphere(fill_opacity=0.5)
sphere2.shift(0.75 * RIGHT)
intersectionCircle = Circle(radius=math.sqrt(1 - 0.75 ** 2))
intersectionCircle.rotate_about_origin(math.radians(90), UP)
self.play(ShowCreation(sphere1), ShowCreation(sphere2), GrowFromCenter(intersectionCircle))
leftDot.set_color(BLUE)
rightDot.set_color(BLUE)
self.wait(WAIT)
plane = Square(side_length=4, fill_color=YELLOW, fill_opacity=0.2)
plane.rotate_about_origin(math.radians(90), UP)
self.play(ShowCreation(plane))
self.wait(5)
self.play(ShrinkToCenter(mainSphere))
self.play(ShrinkToCenter(sphere1), ShrinkToCenter(sphere2))
self.play(ShrinkToCenter(intersectionCircle))
self.play(FadeOut(leftDot), FadeOut(rightDot), FadeOut(centerDot))
self.wait(5)
class PlaneToPerpendicularLine(ThreeDScene):
def construct(self):
WAIT = 1.5
mainTitle = TextMobject("Plane to Perpendicular Line")
mainTitle.to_corner()
self.add_fixed_in_frame_mobjects(mainTitle)
self.move_camera(0.8*np.pi/2, -0.45*np.pi)
self.begin_ambient_camera_rotation()
self.wait(WAIT)
mainSquare = Square(side_length=5, fill_color=YELLOW, fill_opacity=0.2)
self.play(ShowCreation(mainSquare))
self.wait(WAIT)
centerDot = Dot(0, color=BLUE)
self.play(ShowCreation(centerDot))
mainSphere = Sphere(fill_opacity=0.2)
self.play(ShowCreation(mainSphere))
mainLine = Line(2 * LEFT, 2 * RIGHT)
self.play(ShowCreation(mainLine))
line2 = Line(2 * UP, 2 * DOWN)
self.play(ShowCreation(line2))
mainLineEnd1 = Dot(2 * LEFT, color=BLUE)
mainLineEnd2 = Dot(2 * RIGHT, color=BLUE)
self.play(ShowCreation(mainLineEnd1), ShowCreation(mainLineEnd2))
line2End1 = Dot(2 * UP, color=BLUE)
line2End2 = Dot(2 * DOWN, color=BLUE)
self.play(ShowCreation(line2End1), ShowCreation(line2End2))
sphere1 = Sphere(fill_opacity=0.2)
sphere1.shift(LEFT)
sphere2 = Sphere(fill_opacity=0.2)
sphere2.shift(RIGHT)
sphere3 = Sphere(fill_opacity=0.2)
sphere3.shift(UP)
sphere4 = Sphere(fill_opacity=0.2)
sphere4.shift(DOWN)
self.play(ShowCreation(sphere1), ShowCreation(sphere2), ShowCreation(sphere3), ShowCreation(sphere4))
intersectionCircle1 = Circle(radius=math.sqrt(1 - 0.25))
intersectionCircle1.rotate_about_origin(math.radians(90), UP)
intersectionCircle2 = Circle(radius=math.sqrt(1 - 0.25))
intersectionCircle2.rotate_about_origin(math.radians(90), LEFT)
self.play(ShowCreation(intersectionCircle1), ShowCreation(intersectionCircle2))
intersectionDot1 = Dot(math.sqrt(1 - 0.25) * IN, color=BLUE)
intersectionDot2 = Dot(math.sqrt(1 - 0.25) * OUT, color=BLUE)
self.play(ShowCreation(intersectionDot1), ShowCreation(intersectionDot2))
finalLine = Line(2 * IN, 2 * OUT, color=YELLOW)
self.play(ShowCreation(finalLine))
self.wait(3)
self.play(ShrinkToCenter(mainSphere))
self.play(ShrinkToCenter(sphere1), ShrinkToCenter(sphere3))
self.play(ShrinkToCenter(sphere2), ShrinkToCenter(sphere4))
self.play(ShrinkToCenter(intersectionCircle1), ShrinkToCenter(intersectionCircle2), FadeOut(intersectionDot1), FadeOut(intersectionDot2))
self.play(FadeOut(line2), FadeOut(line2End1), FadeOut(line2End2))
self.play(FadeOut(mainLine), FadeOut(mainLineEnd1), FadeOut(mainLineEnd2))
self.wait(5)
class RegularPentagonWithSide(Scene):
def construct(self):
mainTitle = TextMobject("Regular Pentagon")
mainTitle.to_corner()
subtitle = TextMobject("Side of the final pentagon")
subtitle.shift(2.5 * DOWN + 1.5 * RIGHT)
self.add(mainTitle, subtitle)
mainLine = Line(LEFT + 2 * DOWN, RIGHT + 2 * DOWN, color=GREEN)
self.play(ShowCreation(mainLine))
mainLineEnd1 = Dot(LEFT + 2 * DOWN, color=BLUE)
mainLineEnd2 = Dot(RIGHT + 2 * DOWN, color=BLUE)
self.play(ShowCreation(mainLineEnd1), ShowCreation(mainLineEnd2))
self.wait(1)
self.play(Transform(subtitle, mainLine))
# Draw main center vertical perpendicular line
mainLineEnd1.set_color(RED)
mainLineEnd2.set_color(RED)
perp1Arc1 = Arc(math.radians(220), math.radians(-80), arc_center=RIGHT + 2 * DOWN, radius=1.2)
perp1Arc2 = Arc(math.radians(-40), math.radians(80), arc_center=LEFT + 2 * DOWN, radius=1.2)
self.play(ShowCreation(perp1Arc1), ShowCreation(perp1Arc2))
mainLineEnd1.set_color(BLUE)
mainLineEnd2.set_color(BLUE)
self.wait(1)
perp1 = Line(3 * DOWN, 3 * UP)
self.play(ShowCreation(perp1))
mainLineMiddle = Dot(2 * DOWN, color=BLUE)
self.play(ShowCreation(mainLineMiddle))
self.wait(1)
# Draw second vertical perpendicular line
## Extend the main line
mainExtend = Line(RIGHT + 2 * DOWN, 3 * RIGHT + 2 * DOWN)
self.play(ShowCreation(mainExtend))
## Draw points the same distance away
mainLineEnd2.set_color(RED)
perp2Circle = Circle(arc_center=RIGHT + 2 * DOWN, color=RED, radius=0.5)
self.play(ShowCreation(perp2Circle))
mainLineEnd2.set_color(BLUE)
perp2Dot1 = Dot(2 * DOWN + 1.5 * RIGHT, color=BLUE)
perp2Dot2 = Dot(2 * DOWN + 0.5 * RIGHT, color=BLUE)
self.play(ShowCreation(perp2Dot1), ShowCreation(perp2Dot2))
## Draw arcs to find perpendicular line
perp2Dot1.set_color(RED)
perp2Dot2.set_color(RED)
perp2Arc1 = Arc(math.radians(220), math.radians(-80), arc_center=2 * DOWN + 1.5 * RIGHT, radius=0.6)
perp2Arc2 = Arc(math.radians(-40), math.radians(80), arc_center=2 * DOWN + 0.5 * RIGHT, radius=0.6)
self.play(ShowCreation(perp2Arc1), ShowCreation(perp2Arc2))
perp2Dot1.set_color(BLUE)
perp2Dot2.set_color(BLUE)
## Draw perpendicular line
perp2 = Line(3 * DOWN + RIGHT, UP + RIGHT)
self.play(ShowCreation(perp2))
self.wait(1)
# Find point on 2nd perpendicular
mainLineEnd2.set_color(RED)
perp2PointArc = Arc(math.radians(190), math.radians(-140), arc_center=2 * DOWN + RIGHT, radius=2)
self.play(ShowCreation(perp2PointArc))
mainLineEnd2.set_color(BLUE)
perp2Point1 = Dot(RIGHT, color=BLUE)
self.play(ShowCreation(perp2Point1))
self.wait(1)
# Find point on extended main line
mainLineMiddle.set_color(RED)
mainExtendPointArc = Arc(math.radians(80), math.radians(-90), arc_center=2 * DOWN, radius=math.sqrt(5))
self.play(ShowCreation(mainExtendPointArc))
mainLineMiddle.set_color(BLUE)
mainExtendPoint1 = Dot(2 * DOWN + (math.sqrt(5)) * RIGHT, color=BLUE)
self.play(ShowCreation(mainExtendPoint1))
self.wait(1)
# Find top of pentagon
mainLineEnd1.set_color(RED)
rightMainArc = Arc(math.radians(-10), math.radians(110), arc_center=2 * DOWN + LEFT, radius=1 + math.sqrt(5))
self.play(ShowCreation(rightMainArc))
mainLineEnd1.set_color(BLUE)
topDot = Dot((2 - math.sqrt((math.sqrt(5) + 1) ** 2 - 1)) * DOWN, color=BLUE)
self.play(ShowCreation(topDot))
self.wait(1)
# Draw left top of pentagon
mainLineEnd2.set_color(RED)
leftMainArc = Arc(math.radians(80), math.radians(70), arc_center=2 * DOWN + RIGHT, radius=1 + math.sqrt(5))
self.play(ShowCreation(leftMainArc))
mainLineEnd2.set_color(BLUE)
self.wait(1)
# Draw left side length
mainLineEnd1.set_color(RED)
leftSideLengthArc = Arc(math.radians(-10), math.radians(140), arc_center=2 * DOWN + LEFT, radius=2)
self.play(ShowCreation(leftSideLengthArc))
mainLineEnd1.set_color(BLUE)
leftDot = Dot(Common.polarToCartesian(2, math.radians(108), 2 * DOWN + LEFT), color=BLUE)
self.play(ShowCreation(leftDot))
self.wait(1)
# Dot for right side
rightDot = Dot(Common.polarToCartesian(2, math.radians(72), 2 * DOWN + RIGHT), color=BLUE)
self.play(ShowCreation(rightDot))
# Final pentagon drawing
leftBottomSegment = Line(2 * DOWN + LEFT, Common.polarToCartesian(2, math.radians(108), 2 * DOWN + LEFT), color=YELLOW)
self.play(ShowCreation(leftBottomSegment))
self.wait(1)
rightBottomSegment = Line(2 * DOWN + RIGHT, Common.polarToCartesian(2, math.radians(72), 2 * DOWN + RIGHT), color=YELLOW)
self.play(ShowCreation(rightBottomSegment))
self.wait(1)
rightTopSegment = Line(Common.polarToCartesian(2, math.radians(72), 2 * DOWN + RIGHT), (2 - math.sqrt((math.sqrt(5) + 1) ** 2 - 1)) * DOWN, color=YELLOW)
self.play(ShowCreation(rightTopSegment))
self.wait(1)
leftTopSegment = Line(Common.polarToCartesian(2, math.radians(108), 2 * DOWN + LEFT), (2 - math.sqrt((math.sqrt(5) + 1) ** 2 - 1)) * DOWN, color=YELLOW)
self.play(ShowCreation(leftTopSegment))
self.wait(2)
# Clean up working
self.play(FadeOutAndShiftDown(perp1Arc1), FadeOutAndShiftDown(perp1Arc2))
self.play(FadeOutAndShiftDown(perp2Arc1), FadeOutAndShiftDown(perp2Arc2))
self.play(FadeOutAndShiftDown(perp2Circle), FadeOutAndShiftDown(perp2Dot1), FadeOutAndShiftDown(perp2Dot2))
self.play(FadeOutAndShiftDown(rightMainArc), FadeOutAndShiftDown(leftMainArc))
self.play(FadeOutAndShiftDown(perp2PointArc), FadeOutAndShiftDown(perp2Point1), FadeOutAndShiftDown(mainExtendPointArc), FadeOutAndShiftDown(mainExtendPoint1))
self.play(FadeOutAndShift(perp2), FadeOutAndShift(leftSideLengthArc))
self.play(FadeOut(mainExtend))
self.play(FadeOut(perp1), FadeOut(mainLineMiddle))
self.wait(3)
class Common(object):
@staticmethod
def polarToCartesian(distance, angle, center=0):
return sin(angle) * distance * UP + cos(angle) * distance * RIGHT + center