Maggie
Maggie

Reputation: 31

Moving a turtle to the center of a circle

I've just started using the turtle graphics program, but I can't figure out how to move the turtle automatically to the center of a circle (no matter where the circle is located) without it drawing any lines. I thought I could use the goto.() function but it's too specific and I need something general.

Upvotes: 1

Views: 4723

Answers (2)

NanoTera
NanoTera

Reputation: 61

If your rotate 90 degrees left and then move forward one radius length you will be at the centre of the circle (and lifting the pen first to stop it drawing a line as outis said).

for example

import turtle
myT=turtle.Turtle()
# draw your circle 
myT.circle(100)
# rotate so you are looking towards the centre of the circle
myT.left(90)
# lift the pen so no line is drawn
myT.penup()
myT.forward(100)
# put pen down now (if you need to)
myT.pendown()
# rotate back (if you need to)
mtT.right(90)

This is because you are always facing along a tangent to the circle you just drew and the angle of a tangent to a radius is always 90 degrees (right). This is assuming you just drew the circle, a whole lot of trigonometry involved if you want to calculate the location of the centre of some older arbitrary circle!

Upvotes: 0

outis
outis

Reputation: 77400

Use penup to lift the pen and draw nothing while moving.

Upvotes: 2

Related Questions