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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s