How To Draw Ellipse In Python Using Turtle
How to draw ellipse
The ellipse shape could be viewed as iv separated arcs. The two facing each other take the same radius while the ii next to each other have different radius, shown at below.
The python code for above graph is equally follows:
import turtle equally t
t.pu()
t.goto(150, -lx)
t.pd()
t.ht()
t.speed(0)
t.bgcolor(0,0,0)
t.seth(45)
t.pensize(10)
for n in range(2):
t.color(1,0,0)
t.circle(120,90)
t.color(0,0,1)
t.circle(250, 90)
t.done()
How to draw egg shape
An egg shape is made upward of four arcs with 3 different radius, as shown in the graph below.
import turtle equally t
import math
RADIUS = 150
OFFSET = 2 - math.sqrt(two) # offset is around 0.586
screen = t.Screen()
screen.setup(600,600, 0, 0)
t.speed(0)
t.pensize(10)
t.bgcolor(0,0,0)
t.ht()
t.upward()
t.goto(-50,200)
t.down()
t.seth(180)
t.color(1,0,0)
t.circle(RADIUS,180)
t.colour(0,0,1)
t.circle(2*RADIUS,45)
t.color(0,one,0)
t.circle(OFFSET * RADIUS,90)
t.color(0,0,1)
t.circumvolve(two*RADIUS,45)
t.done()
Using math sin/cos method
The sin/cos method in math module could be used to draw ellipse shape or egg shape as well. Any bespeak on a ellipse/egg shape, it'south X cooridnate is mapped by math.cos method and Y cooridnate mapped by math.sin method. Shown in the graph below. For the angle α, the sine part gives the ratio of the length of the opposite side to the length of the hypotenuse.
To define the sine role of an acute angle α, offset with a right triangle that contains an angle of measure α; in the accompanying figure, angle α in triangle ABC is the angle of interest. The three sides of the triangle are named as follows:
- The opposite side is the side opposite to the angle of interest, in this example side a.
- The hypotenuse is the side opposite the right angle, in this case side h. The hypotenuse is always the longest side of a right-angled triangle.
- The adjacent side is the remaining side, in this case side b. Information technology forms a side of (and is adjacent to) both the bending of interest (angle A) and the right angle.
One time such a triangle is called, the sine of the angle is equal to the length of the opposite side, divided by the length of the hypotenuse:
Mapped to a circle, the sin/cos could exist displayed as follows:
To show the ellipse and circumvolve angles in one graph:
Some mutual angles (θ) shown on the unit of measurement circle. The angles are given in degrees and radians, together with the corresponding intersection point on the unit circle, (cos(θ), sin(θ)).
Draw Ellipse with Math Role
import turtle as t
import math
def spring(pos):
t.pu()
t.goto(pos)
t.pd()
jump((100,0))
r1, r2= 100, 180
for northward in range(361):
rad = math.pi / 180
sin = math.sin(n * rad)
cos = math.cos(n * rad)
ten = r2 * cos
y = r1 * sin
if n == 0:
jump((ten,y))
else:
t.goto(x,y)
t.done()
Source: https://codeguru.academy/?p=431
Posted by: yateskinviout.blogspot.com

0 Response to "How To Draw Ellipse In Python Using Turtle"
Post a Comment