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.


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 *


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

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