Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def PointFit(points):
avg = AvgPoint(points)
dev = 0
max_dev = 0
for p in points:
v = vector.sub(p[:3], avg)
d = vector.dot(v, v)
max_dev = max(d, max_dev)
dev += d
dev /= len(points)
return avg, dev**.5, max_dev**.5
r1 = lmap(lambda y, z : beta[6] - vector.dot(y, z), m, g)
r0 = lmap(lambda y : efit[3]**2 - vector.dot(y, y), m)
#return r0
def right_angle(v1, v2):
x = vector.Vector(v1[0], v1[1])
y = vector.Vector(v2[0], v2[1])
dot = vector.dot(x, y)
_angle = math.acos(dot / x.length() / y.length())
if x[0] * y[1] < y[0] * x[1]:
_angle = 2 * math.pi - _angle
return _angle
line_fit = [datamean, vv[0]]
plane_fit = [datamean, vv[2]]
line_dev = 0
max_line_dev = 0
plane_dev = 0
max_plane_dev = 0
for p in data:
t = vector.dot(p, line_fit[1]) - vector.dot(line_fit[0], line_fit[1])
q = lmap(lambda o, n : o + t*n, line_fit[0], line_fit[1])
v = vector.sub(p, q)
d = vector.dot(v, v)
max_line_dev = max(d, max_line_dev)
line_dev += d
t = vector.dot(p, plane_fit[1]) - vector.dot(plane_fit[0], plane_fit[1])
v = lmap(lambda b : t*b, plane_fit[1])
d = vector.dot(v, v)
max_plane_dev = max(d, max_plane_dev)
plane_dev += d
line_dev /= len(points)
plane_dev /= len(points)
line = [line_fit, line_dev**.5, max_line_dev**.5]
plane = [plane_fit, plane_dev**.5, max_plane_dev**.5]
return line, plane
line_dev = 0
max_line_dev = 0
plane_dev = 0
max_plane_dev = 0
for p in data:
t = vector.dot(p, line_fit[1]) - vector.dot(line_fit[0], line_fit[1])
q = lmap(lambda o, n : o + t*n, line_fit[0], line_fit[1])
v = vector.sub(p, q)
d = vector.dot(v, v)
max_line_dev = max(d, max_line_dev)
line_dev += d
t = vector.dot(p, plane_fit[1]) - vector.dot(plane_fit[0], plane_fit[1])
v = lmap(lambda b : t*b, plane_fit[1])
d = vector.dot(v, v)
max_plane_dev = max(d, max_plane_dev)
plane_dev += d
line_dev /= len(points)
plane_dev /= len(points)
line = [line_fit, line_dev**.5, max_line_dev**.5]
plane = [plane_fit, plane_dev**.5, max_plane_dev**.5]
return line, plane
## glEnd()
# SOLIDS
## glColor(1, 1, 1)
## glBegin(GL_TRIANGLES)
## for vertex in brush_triangles:
## glVertex(*vertex)
## glEnd()
glBegin(GL_TRIANGLES)
for solid in render_solids:
if not solid.is_displacement:
glColor(*solid.colour) # Flat Colour Unshaded
for side_index, index_range in enumerate(solid.face_tri_map):
normal = solid.planes[side_index][0]
Kd = (vector.dot(normal, (1, 1, 1)) / 16) + .75
glColor(*[Kd * x for x in solid.colour])
start, end = index_range
for vertex in solid.triangles[start:end]:
glVertex(*vertex)
glEnd()
# DISPLACEMENTS
glBegin(GL_TRIANGLES)
glColor(.5, .5, .5)
for solid in render_solids:
if solid.is_displacement:
glColor(1, 1, 1) # Hammer Default
for i, points in solid.displacement_triangles.items():
for point, alpha, normal in points:
Kd = (vector.dot(normal, (1, 1, 1)) / 16) + .75
# clamped from 0.75 to 0.75 + 1/32
def ComputeDeviation(points, fit):
m, d = 0, 0
for p in points:
v = vector.sub(p[:3], fit[:3])
m += (1 - vector.dot(v, v) / fit[3]**2)**2
if len(fit) > 4:
n = vector.dot(v, p[3:]) / vector.norm(v)
if abs(n) <= 1:
ang = math.degrees(math.asin(n))
d += (fit[4] - ang)**2
else:
d += 1e111
m /= len(points)
d /= len(points)
return [m**.5, d**.5]