-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometry.py
More file actions
35 lines (27 loc) · 977 Bytes
/
Geometry.py
File metadata and controls
35 lines (27 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'''
Author : Asim Krishna Prasad
Aim :
1> Basic geometry functions to assist ChessBoard.py
'''
from math import *
# Function to get distance between two points in 2-D plane
def getPointsDistance((x1, y1), (x2, y2)):
return int(sqrt((y2 - y1) ** 2 + (x2 - x1) ** 2))
# Function to getgit mid-point of a line segment
def getMidPoint((x1, y1), (x2, y2)):
return int((x1 + x2) / 2), int((y1 + y2) / 2)
# Function to get "Segments" equal segments on a line-segment
# returns a list of "Segments + 1" equidistant points on line-segment
def partitionLine(SP, EP, Segments):
Points = Segments + 1
ls = [(0, 0) for x in range(Points)]
ls[0] = SP
ls[8] = EP
ls[4] = getMidPoint(ls[0], ls[8])
ls[2] = getMidPoint(ls[0], ls[4])
ls[1] = getMidPoint(ls[0], ls[2])
ls[3] = getMidPoint(ls[2], ls[4])
ls[6] = getMidPoint(ls[4], ls[8])
ls[5] = getMidPoint(ls[4], ls[6])
ls[7] = getMidPoint(ls[8], ls[6])
return ls