简体   繁体   中英

How to draw equally spaced dots on a circle in manim?

In manimce,

How to draw equally spaced dots on a circle as shown below?

在此处输入图片说明

I can calculate each point's coordinates by hand and input them, but is there an easy build in way to input dots in manim?


Image credits

The documentation explains that the Circle object has a method point_at_angle . PointAtAngle Example

The point_at_angle method takes a single argument which is the angle of the point along the circle in radians.

Here is some code to draw a green circle and 16 red dots on its circumference:

from manim import *

class PointsOnCircle(Scene):
    def construct(self):
        circle = Circle(radius=3.0, color=GREEN)
        # Number of points required
        num_points = 16
        # Calculate each angle
        angles = [n * (360 / num_points) for n in range(num_points)]
        # Points on circumference of circle
        points = [circle.point_at_angle(n*DEGREES) for n in angles]
        # Create circles at each point
        circles = [Circle(radius=0.05, color=RED, fill_opacity=1).move_to(p) for p in points]
        # Add the circle to the scene
        self.add(circle)
        # Add each of the points to the scene
        for c in circles:
            self.add(c)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM