def quickHullAlg(points, r, q): furthestPoint = [] #In the inital call q and r two points with the highest and lowest y value maxdist = -1 if points == []: return if len(points) == 1: furthestPoint = points for p in points: temp = sqrt((r[0] - p[0])**2 + (r[1] - p[1])**2) + sqrt((q[0] - p[0])**2 + (q[1] - p[1])**2) #distance of p from q and p added together if(temp > maxdist): furthestPoint = p #finds the furthest point from the line r, q maxdist = temp if(furthestPoint == []): return points.remove(furthestPoint) triangle = r + q + furthestPoint triList.append(triangle) #adding a triangle to the set to print out [set0,set1] = Triangles.splitPoints(r,furthestPoint,q,points) [set0,set2] = Triangles.splitPoints(q,furthestPoint,r,points) quickHullAlg(set1,r,furthestPoint) quickHullAlg(set2,furthestPoint, q)
def quickHullAlg(points, r, q): furthestPoint = [ ] #In the inital call q and r two points with the highest and lowest y value maxdist = -1 if points == []: return if len(points) == 1: furthestPoint = points for p in points: temp = sqrt((r[0] - p[0])**2 + (r[1] - p[1])**2) + sqrt( (q[0] - p[0])**2 + (q[1] - p[1])**2) #distance of p from q and p added together if (temp > maxdist): furthestPoint = p #finds the furthest point from the line r, q maxdist = temp if (furthestPoint == []): return points.remove(furthestPoint) triangle = r + q + furthestPoint triList.append(triangle) #adding a triangle to the set to print out [set0, set1] = Triangles.splitPoints(r, furthestPoint, q, points) [set0, set2] = Triangles.splitPoints(q, furthestPoint, r, points) quickHullAlg(set1, r, furthestPoint) quickHullAlg(set2, furthestPoint, q)
def quickHullStart(points): #Setup for the QuickHull Algorithm maxY = -1 minY = float('inf') for p in points: #getting highest and lowest points (r, q) if p[1] > maxY: maxY = p[1] q = p if p[1] < minY: minY = p[1] r = p points.remove(r) points.remove(q) hull = r+q [set0,set1] = Triangles.splitPoints(r,q,q,points) #Spliting points in half by a line with the Highest and lowest points quickHullAlg(set0, r,q) quickHullAlg(set1, r,q)
def quickHullStart(points): #Setup for the QuickHull Algorithm maxY = -1 minY = float('inf') for p in points: #getting highest and lowest points (r, q) if p[1] > maxY: maxY = p[1] q = p if p[1] < minY: minY = p[1] r = p points.remove(r) points.remove(q) hull = r + q [set0, set1] = Triangles.splitPoints( r, q, q, points ) #Spliting points in half by a line with the Highest and lowest points quickHullAlg(set0, r, q) quickHullAlg(set1, r, q)
if __name__ == "__main__": # HW4 # IMport Points points_np = np.genfromtxt('hw3data/data_small.xyz') # (X,Y,Z) # Scipi triangulation tri = Delaunay(points_np[:, 0:2]) # Plot Scipy Result plt.triplot(points_np[:, 0], points_np[:, 1], tri.simplices, linewidth=0.25) # plt.plot(points_np[:, 0], points_np[:, 1], 'o', markersize=0.2) # plt.savefig('testset4_sci.png', dpi=600) # Triangulation object initialization trinagulation = Triangles.Triangulation(tri.simplices, points_np) convex = trinagulation.convexPoints() trinagulation.interpolate() new_point_hight_bq = trinagulation.newHight(Triangles.Point(10, 80, None)) new_point_hight_bl = trinagulation.newHight( Triangles.Point(11.0, 120.0, None)) print([[10, 80, np.round(new_point_hight_bq, 3)], [11.0, 120.0, np.round(new_point_hight_bl, 3)]]) restrictions = np.genfromtxt('hw3data/constrains.txt', delimiter=",") points_np_my = trinagulation.updateRestrictions(restrictions.tolist()) plt.axis('equal') plt.show() for i in range(0, convex.shape[0], 2): plt.plot(convex[i:i + 2, 0], convex[i:i + 2, 1], 'bo-')
for groove in adjustedGrooveLines: l1 = groove[0] l2 = groove[1] cv2.line(img, (l1[0][0], l1[0][1]), (l1[1][0], l1[1][1]), (255, 255, 0), 1) cv2.line(img, (l2[0][0], l2[0][1]), (l2[1][0], l2[1][1]), (255, 255, 0), 1) cv2.imshow("Adjusted Lines", img) cv2.waitKey(0) cv2.destroyAllWindows() print(adjustedGrooveLines) print("Groove Score", scoreGrooves(GrooveLines, corners)) print("Adjusted Groove Score", scoreAdjustedGroove(adjustedGrooveLines)) # Score Diagonal grooves img = np.copy(images[2]) grayImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) smooth = nr.rmSpecales(grayImg) smooth = nr.rmSpecales(grayImg) smooth = nr.smoothing(smooth) edges = cv2.Canny(smooth, 50, 75) TriLines = Triangles.GetTriangles(img, Tribases, edges) # TriLines = [ # [[[597, 471], [456, 362]], [[605, 493], [481, 604]],np.array([[461, 602],[442, 342]], dtype=np.int32)], # [[[674, 411], [787, 309]], [[637, 419], [496, 310]], np.array([[491, 296],[756, 303]], dtype=np.int32)], # [[[725, 500], [848, 619]], [[724, 466], [837, 364]], np.array([[818, 355],[836, 620]], dtype=np.int32)], # [[[650, 544], [526, 655]], [[685, 541], [808, 660]], np.array([[785, 673],[522, 662]], dtype=np.int32)] # ] print("Triangle Score", scoreTri(TriLines, img))