def transform(point_array, transformation_matrix): out = [] for p in point_array: p1 = transformation_matrix * [p.x, p.y, 1] # matrix multiplication p1 = p1[0] # get column vector if p1[2] is not 1: p1[0] /= p1[2]; p1[1] /= p1[2]; p1[2] = 1 # Homogeneous coordinates out.append( Helios.Point(int(p1[0]), int(p1[1]), p.r, p.g, p.b, p.i) ) return out
def barrel_distort(point_array, k=0, cx=0, cy=0): out = [] for p in point_array: dx = (p.x - cx) / 4095 # distance from center of distortion (but scaled to 0..1) dy = (p.y - cy) / 4095 d = math.sqrt( dx*dx + dy*dy ) dd = d * (1 + k * d * d) # distorted distance if d == 0: d = 1 nx = cx + dx/d*dd * 4095 ny = cy + dy/d*dd * 4095 out.append( Helios.Point(int(nx), int(ny), p.r, p.g, p.b, p.i) ) return out
def interpolate(point_array, fullwidth_steps = 100, close = False): step_size = 0xFFF / fullwidth_steps # print(step_size) out = [] l = len(point_array)-1 if close: l += 1 for i in range(l): p0 = point_array[i] p1 = point_array[(i+1) % len(point_array)] d = dist(p0.x, p0.y, p1.x, p1.y) n = int(d / step_size) # number of interpolated points (including start and end) if n < 2: n = 2 # include at least start and end for j in range(n): a = j / (n-1) # interpolation parameter [0, 1] attrs = interp_attrs(['x','y','r','g','b','i'] , p0, p1, a) out.append( Helios.Point(*attrs) ) # print(a, attrs) # print(i, d, n) return out