def add_triedron(self, length=10, width=1, arrlen=1, xcolor=pyservoce.red, ycolor=pyservoce.green, zcolor=pyservoce.blue): self.xaxis = pyservoce.draw_arrow(pyservoce.point3(0, 0, 0), pyservoce.vector3(length, 0, 0), clr=xcolor, arrlen=arrlen, width=width) self.yaxis = pyservoce.draw_arrow(pyservoce.point3(0, 0, 0), pyservoce.vector3(0, length, 0), clr=ycolor, arrlen=arrlen, width=width) self.zaxis = pyservoce.draw_arrow(pyservoce.point3(0, 0, 0), pyservoce.vector3(0, 0, length), clr=zcolor, arrlen=arrlen, width=width) self.dispobjects.append(self.xaxis) self.dispobjects.append(self.yaxis) self.dispobjects.append(self.zaxis)
def point3(*args): args = [evalcache.unlazy_if_need(a) for a in args] if len(args) == 1: if args[0] is None: return point3(0, 0, 0) return point3(*args[0]) return pyservoce.point3(*args)
def numpy_highmap(arr): #result = numpy.ndarray((arr.shape[0], arr.shape[1]), dtype=pyservoce.point3) result = numpy.ndarray(arr.shape, dtype=pyservoce.point3) for i in range(arr.shape[0]): for j in range(arr.shape[1]): result[i, j] = pyservoce.point3(i, j, arr[i, j]) return result
def restore_ellipse_centers(apnt, bpnt, r1, r2, phi): """ Поиск центра двумерного элипса по радиусам, углу наклона главной оси и двум точкам. """ rot = rotateZ(phi) irot = rot.inverse() x1, y1, _ = irot(apnt) x2, y2, _ = irot(bpnt) a, b = r1**2, r2**2 if abs(a - b) < 1e-5 and abs(sqrt((x1 - x2)**2 + (y1 - y2)**2) - r1 * 2) < 1e-5: return point3((apnt.x + bpnt.x) / 2, (apnt.y + bpnt.y) / 2), point3( (apnt.x + bpnt.x) / 2, (apnt.y + bpnt.y) / 2) if abs(x1 - x2) < 1e-5: y01 = (y1 + y2) / 2 x01 = x1 - sqrt(-a * b * (-4 * b + y1**2 - 2 * y1 * y2 + y2**2)) / (2 * b) y02 = (y1 + y2) / 2 x02 = x1 + sqrt(-a * b * (-4 * b + y1**2 - 2 * y1 * y2 + y2**2)) / (2 * b) elif abs(y1 - y2) < 1e-5: y01 = y1 - sqrt(-a * b * (-4 * a + x1**2 - 2 * x1 * x2 + x2**2)) / (2 * a) x01 = (x1 + x2) / 2 y02 = y1 + sqrt(-a * b * (-4 * a + x1**2 - 2 * x1 * x2 + x2**2)) / (2 * a) x02 = (x1 + x2) / 2 else: y01 = -(-a * y1**2 + a * y2**2 - b * x1**2 + b * x2**2 + (2 * b * x1 - 2 * b * x2) * (x1 / 2 + x2 / 2 - sqrt(-a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2) * (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / (2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)))) / (2 * a * (y1 - y2)) x01 = x1 / 2 + x2 / 2 - sqrt( -a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2) * (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / ( 2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) y02 = -(-a * y1**2 + a * y2**2 - b * x1**2 + b * x2**2 + (2 * b * x1 - 2 * b * x2) * (x1 / 2 + x2 / 2 + sqrt(-a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2) * (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / (2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)))) / (2 * a * (y1 - y2)) x02 = x1 / 2 + x2 / 2 + sqrt( -a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2) * (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / ( 2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) c0, c1 = point3(x01, y01), point3(x02, y02) c0, c1 = rot(c0), rot(c1) return c0, c1
(-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / (2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)))) / (2 * a * (y1 - y2)) x02 = x1 / 2 + x2 / 2 + sqrt( -a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2) * (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / ( 2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) c0, c1 = point3(x01, y01), point3(x02, y02) c0, c1 = rot(c0), rot(c1) return c0, c1 def restore_circle_centers(apnt, bpnt, r): """ Поиск центра двумерной окружности по радиусу, углу наклона главной оси и двум точкам. """ return restore_ellipse_centers(apnt, bpnt, r, r, 0) ## TEST if __name__ == "__main__": print(restore_ellipse_centers(point3(15, 10), point3(5, 10), 5, 5, 0))
def segment(pnt0, pnt1): return pyservoce.segment(pyservoce.point3(pnt0), pyservoce.point3(pnt1))
def point3(*arg): if isinstance(arg[0], pyservoce.point3): return arg[0] return pyservoce.point3(*arg)