CoCalc
SharedPresentation.sagewsOpen in CoCalc

Kpoint

class singlevertex(object):

# variables for specifying arbitrary labeled singlevertex with arbitrary angle units, i.e. degrees/radians/other

# 2n-tuple of positive real numbers with equal alternate sums
Kpoint = []
# 2n-tuple of real numbers beginning with 0, alternating up/down, last term > 0

alternate_sum = 0
total_sum = 0

# number of creases emanating from central vertex
degree = 0
# half the vertex degree
n = 0

# unit conversions
intr2deg = 1
deg2intr = 1
Kpoint_deg = []

# stacking
stacking = []
stack_diagram = []
Vpoint = []

# embedding in the plane
layer_height = 0
point_count_2d = 0
points_2d = []
polygon_2d = []
plot_2d = []
delta_steps = 10
delta_step = 1.0
animate_2d = 0

# embedding in 3-space
point_count_3d = 0
polygon_3d = []
# (x,y,z) position of central vertex
central_vertex = []

def __repr__(self):
return "singlevertex"

# ************
#  horizontal
# ************

def set_Kpoint(self, v):
# TODO: verify input
self.Kpoint = v
self.evaluate_metrics()

# TODO: verify input
self.evaluate_metrics()

for i in range(len(v) - 1):
sign = 1 - (i % 2) * 2

Kpoint = []
for i in range(len(v) // 2):
Kpoint.append(v[2 * i + 1] - v[2 * i])
Kpoint.append(v[2 * i + 1] - v[(2 * i + 2) % len(v)])
return Kpoint

def evaluate_metrics(self):
self.degree = len(self.Kpoint)
self.n = self.degree // 2

self.total_sum = sum(self.Kpoint)
self.alternate_sum = self.total_sum / 2

self.intr2deg = 180 / self.alternate_sum
self.deg2intr = self.alternate_sum / 180

self.Kpoint_deg = [x * self.intr2deg for x in self.Kpoint]

# **********
#  vertical
# **********

def set_stacking(self, v):
self.stacking = v
self.Vpoint = self.stacking2Vpoint(self.stacking)

def stacking2Vpoint(self, v):
Vpoint = []
for i in range(len(v)):
Vpoint.append(abs(v[(i+1)%len(v)] - v[i]))
return Vpoint

# ***************
#  stack diagram
# ***************

# ******************
#  planar embedding
# ******************

def construct_planar_embedding(self, color='black', thickness=3, delta_steps=10):
self.delta_steps = delta_steps
self.delta_step = 1.0 / (self.delta_steps - 1)
self.polygon_2d = []
self.plot_2d = []
for i in range(delta_steps):
self.compute_layer_height()
self.compute_points_2d()
poly = polygon2d(self.points_2d, color=color, fill=False, thickness=thickness)
self.polygon_2d.append(poly)
self.plot_2d.append(plot(poly))
self.animate_2d = animate(self.plot_2d + self.plot_2d[::-1])

for i in range(self.degree):
for j in range(self.degree):
if i != j and self.parity(i) * diff > 0 and abs(diff) < self.isolation_radius:

def compute_layer_height(self):
self.layer_height = self.isolation_radius * sqrt(2) / (self.degree - 1.0)

def compute_points_2d(self):
self.point_count_2d = self.degree * 3
self.points_2d = []
for i in range(self.degree):
i1 = (i + 1) % self.degree
ipar = self.parity(i)
x = self.shadow[i] + (ipar * self.Vpoint[i] * self.isolation_radius) / (self.degree - 1)
y = self.stacking[i] * self.layer_height
self.points_2d.append((x,y))
x = self.shadow[i1] - (ipar * self.Vpoint[i1] * self.isolation_radius) / (self.degree - 1)
y = self.stacking[i] * self.layer_height
self.points_2d.append((x,y))
x = self.shadow[i1] - (ipar * (2 - sqrt(2)) * self.Vpoint[i1] * self.isolation_radius) / (2 * self.degree - 2)
y = 0.5 * (self.stacking[i] + self.stacking[i1]) * self.layer_height
self.points_2d.append((x,y))

# arithmetic tools

# subtract 1 modulo n within [1,...,n]
def mod_decrement(self, i,n):
return (i+n-2)%n+1

# add 1 modulo n within [1,...,n]
def mod_increment(self, i,n):
return (i%n)+1

# 1 if even, -1 if odd
def parity(self, i):
return 1 if i % 2 == 0 else -1

def get_polygons(self):
return 0


A = singlevertex()
k = [1,2,3,3,2,1]
A.set_Kpoint(k)
print(A.alternate_sum)
print(A.total_sum)
print(A.Kpoint_deg)

# s = [0, 3, -1, 5]
# print(A.Kpoint)
# print(A.alternate_sum)
# print(A.total_sum)
# print(A.Kpoint_deg)

stacking = [4,5,6,1,2,3]
A.set_stacking(stacking)
print(A.stacking)
print(A.Vpoint)

A.construct_planar_embedding(delta_steps=10)

A.animate_2d.show(gif=True)
# @interact
# def diagram(step=(0.0, 1.0, A.delta_step)):
#     show(A.polygon_2d[int(step / A.delta_step)])

[0, 1, -1, 2, -1, 1] 6 12 [30, 60, 90, 90, 60, 30] [1/6*pi, 1/3*pi, 1/2*pi, 1/2*pi, 1/3*pi, 1/6*pi] [4, 5, 6, 1, 2, 3] [1, 1, 5, 1, 1, 1]


@interact
def func(k = slider(0, 10, .1), j = (-10, 10), l = range_slider(-5, 5)):
print("k: %s" % k)
print("j: %s" % j)
print("l: [%s, %s]" % l)