Python code

import itertools import time import math from turtle import * import random # Takes a polygon p and returns its perimeter def perimeter(p): perim = 0 # perimeter numPoints = len(p) for i in range(numPoints): # for the P above, i will count 0, 1, 2, 3 perim = perim + EKdistance(p[i], p[(i+1)%numPoints]) print perim # finds the distance between points p and q # p and q are both tuples p=(0,3) q=(1,5) def EKdistance(p, q): return math.sqrt((p[0]-q[0])**2+(p[1]-q[1])**2) def Is_Counter_Clockwise(P): sumDet = 0 numPoints = len(P) for i in range (numPoints): sumDet = sumDet + EKdet(P[i], P[(i+1)%numPoints]) if sumDet < 0: return False else: return True

Advertisements