def fill(xPoly, yPoly, alpha, d): polyArray = [] x, y = rotate(xPoly, yPoly, alpha) for i in range(len(x)): polyArray.append((x[i], y[i])) poly = sympy.Polygon(*polyArray) reverse = False real = 0 printed = 0 minX = min(x) minY = min(y) maxX = max(x) maxY = max(y) count = (maxY - minY) / d inter = [] xFilled = [] yFilled = [] while printed < count: real += d l = sympy.Line((minX, minY + real), (maxY, minY + real)) inter.append(poly.intersection(l)) for i in range(len(inter[printed]) - 1): tempL = sympy.Segment(inter[printed][i], inter[printed][i + 1]) if poly.encloses_point(tempL.midpoint): if reverse: inter[printed] = np.flip(inter[printed], axis=0) xFilled.append(inter[printed][i][0]) xFilled.append(inter[printed][i + 1][0]) yFilled.append(inter[printed][i][1]) yFilled.append(inter[printed][i + 1][1]) reverse = not reverse print(printed) printed += 1 xFinal, yFinal = rotate(xFilled, yFilled, -1 * alpha) return xFinal, yFinal
def goodeFunction(event, x, y, flags, params): #Defining unit distance as global to avoid errors global unitDistance pointsList = params[0] if (event == cv2.EVENT_LBUTTONDOWN) and ( len(pointsList) < 3): #Left Click and <5 points exist #Draw Point cv2.circle(img, (x, y), 2, (0, 0, 255), cv2.FILLED) #Add to points list pointsList.append((x, y)) print("Point drawn at:" + str(x) + "," + str(y)) print(pointsList) if len(pointsList) == 1: #Placing Point A of triangle print("Vertex A drawn, please place vertex B on image") elif len(pointsList) == 2: #Placing measuring point #Draw Line cv2.line(img, pointsList[0], pointsList[1], (0, 0, 255), 2) print("Vertex B placed, please draw vertex C") elif len(pointsList) == 3: #Draw Line cv2.line(img, pointsList[1], pointsList[2], (0, 0, 255), 2) cv2.line(img, pointsList[0], pointsList[2], (0, 0, 255), 2) edgeAB = sympy.Segment(pointsList[0], pointsList[1]) edgeBC = sympy.Segment(pointsList[1], pointsList[2]) edgeAC = sympy.Segment(pointsList[0], pointsList[2]) lengthAB = edgeAB.length * unitDistance lengthBC = edgeBC.length * unitDistance lengthAC = edgeAC.length * unitDistance #print("Shortest distance is: ",shortestDistance) print("Length of edge AB is: ", str(float(lengthAB))) print("Length of edge BC is: ", str(float(lengthBC))) print("Length of edge AC is: ", str(float(lengthAC)))
def geometry(): ''' API endpoint used to solve the revist geometry problem ''' data = request.get_json() if "input" in data: data = data["input"] points_arr_shape = [] for i in data['shapeCoordinates']: points_arr_shape.append(sympy.Point(i["x"], i["y"])) line_array_shape = [] for i in range(len(points_arr_shape) - 1): line_array_shape.append( sympy.Segment(points_arr_shape[i], points_arr_shape[i + 1])) line_array_shape.append( sympy.Segment(points_arr_shape[0], points_arr_shape[-1])) line_points = [] for i in data['lineCoordinates']: line_points.append(sympy.Point(i["x"], i["y"])) main_line = sympy.Line(line_points[0], line_points[1]) intersections = [] output = [] for i in line_array_shape: res = sympy.geometry.intersection(i, main_line) if (len(res)): res = list(res[0]) output.append({ "x": round(float(res[0]), 2), "y": round(float(res[1]), 2), }) return jsonify(output)
def _clip_path(origin, radius, path): path = np.array(path) prev_pt = origin while len(path) > 0: next_pt = path[0] d = np.linalg.norm(next_pt - origin) if d < radius: path = path[1:] else: intersections = sympy.intersection( sympy.Segment(prev_pt, next_pt), sympy.Circle(origin, radius)) # intersection might not actually happen due to limited # fp precision in np.linalg.norm. if not, continue. if intersections: pt = intersections[0].evalf() origin = np.array([pt.x, pt.y], dtype=path.dtype) return np.vstack([[origin], path]) else: path = path[1:] return path
def silverFunction(event, x, y, flags, params): #Defining unit distance as global to avoid errors global unitDistance pointsList = params[0] if (event == cv2.EVENT_LBUTTONDOWN) and ( len(pointsList) < 3): #Left Click and <3 points exist #Draw Point cv2.circle(img, (x, y), 2, (0, 0, 255), cv2.FILLED) #Add to points list pointsList.append((x, y)) print("Point drawn at:" + str(x) + "," + str(y)) print(pointsList) #Factor used in extending line (Change to extend lines more or less) extensionFactor = 450 if len(pointsList) == 1: #Placing Point of elevation #Extend Line points startPointX = pointsList[0][0] - extensionFactor startPointY = pointsList[0][1] startPoint = (startPointX, startPointY) endPointX = pointsList[0][0] + extensionFactor endPointY = pointsList[0][1] endPoint = (endPointX, endPointY) #Draw Line cv2.line(img, startPoint, endPoint, (0, 0, 255), 2) print("Please draw point to draw vertical line") elif len(pointsList) == 2: #Draw vertical line #Extend Line points startPointX = pointsList[1][0] startPointY = pointsList[1][1] - extensionFactor startPoint = (startPointX, startPointY) endPointX = pointsList[1][0] endPointY = pointsList[1][1] + extensionFactor endPoint = (endPointX, endPointY) #Draw Line cv2.line(img, startPoint, endPoint, (0, 0, 255), 2) print("Please draw measuring point") elif len(pointsList) == 3: #Placing measuring point #Extend Line points startPointX = pointsList[1][0] startPointY = pointsList[1][1] - extensionFactor startPoint = (startPointX, startPointY) endPointX = pointsList[1][0] endPointY = pointsList[1][1] + extensionFactor endPoint = (endPointX, endPointY) s1 = sympy.Segment(startPoint, endPoint) shortestDistance = s1.distance(pointsList[2]) measuredDistance = shortestDistance * unitDistance #print("Shortest distance is: ",shortestDistance) print("Measured distance is: ", measuredDistance) #Intersection point is x-coordinate of vertical line and y-coordinate of measuring point intersectionPoint = (startPointX, pointsList[2][1]) #Draw line between measuring point and Frankfort line cv2.line(img, pointsList[2], intersectionPoint, (0, 0, 255), 2)
def __init__(self, args): ''' SegmentModified class ''' self.obj = sym.Segment(*args)