#!/usr/bin/env python3 class Triangle(): #given segment def __init__(self,_a,_b,_c): self.a=_a self.b=_b self.c=_c def __repr__(self): return "Triangle:("+str(self.a)+","+str(self.b)+","+str(self.c)+")" # Center of gravity centered on #a # @return u how much to b # @return v how much in the c direction def barycentric(self,p): #How to use barycentric coordinates #http://www.blackpawn.com/texts/pointinpoly/default.html ca = self.c-self.a ba = self.b-self.a pa = p-self.a #Calculate dot product dotca = ca.dot(ca) dotcba = ca.dot(ba) dotcpa = ca.dot(pa) dotba = ba.dot(ba) dotbpa = ba.dot(pa) #Calculation of barycentric coordinates invDenom = 1 / (dotca * dotba - dotcba * dotcba); u = (dotba * dotcpa-dotcba*dotbpa)*invDenom v = (dotca * dotbpa - dotcba * dotcpa) * invDenom return u,v # Whether there is a point inside the triangle def isContain(self,p): u,v=self.barycentric(p) inkex.errormsg("\n u="+str(u)+" v="+str(v)) If #u=v=0, the same point as the triangle point #Check if there is a point in the triangle return (u > 0) and (v > 0) and (u + v < 1) def toSVG(self): return str(self.a.x)+","+str(self.a.y)+","+str(self.b.x)+","+str(self.b.y)+","+str(self.c.x)+","+str(self.c.y) # Is the arrangement of vertices a, b, c clockwise? def isClockWise(self): circle=self.circumcircle() center=circle.center aTob=self.b-self.a aToc=self.c-self.a #Let's find the cross product cross=aTob.cross(aToc) inkex.errormsg(" cross"+str(cross)) if(cross>0): return True return False#Counterclockwise def circumcircle(self): #Find the length of each side ab=(self.a-self.b).length() bc=(self.b-self.c).length() ca=(self.c-self.a).length() s=(ab+bc+ca)/2.0; area=math.sqrt(s*(s-ab)*(s-bc)*(s-ca)); maxlength=0 if(maxlength