Mid-point of a line segment

From Devipedia

Jump to: navigation, search

Our two points can also be used to find the midpoint of a line segment.

http://upload.wikimedia.org/math/d/e/e/deecdda2b6747bacf9382133e6d045f4.png

Here I modify the script slightly to find the midpoint of our line and place a blue dot on it.


from turtle import *
from math import *

setworldcoordinates(-15,-15,15,15)

# define our points
x1 = 12.0
x2 = 2.0
y1 = 8.0
y2 = 3.0

penup()
goto(x1,y1)
pendown()
dot(10, 'red')  # the first point
goto(x2,y2)     # draws a thin line to the second point
dot(10, 'red')  # the second point

midX = (x1+x2)/2
midY = (y1+y2)/2

goto(midX, midY)# midpoint of the line segment
dot(10, 'blue') # draw a blue dot

Okay this is important but fairly boring stuff. Moving on...

Next: Gradient of a line segment

Personal tools