In [1]:
import splipy as sp
import numpy as np
import matplotlib.pyplot as plt
import splipy.curve_factory as curve_factory
In [2]:
crv = curve_factory.n_gon(6) # create a sample curve
t0 = crv.start() # parametric starting point
t1 = crv.end() # parametric end point
t = np.linspace(t0, t1, 361) # uniform grid of 361 evaluation points on the parametric domain
x = crv(t)
plt.plot(x[:,0], x[:,1]) # plot curve
crv.rotate(10.0/360*2*np.pi) # rotate by 10 degrees (input is in radians)
x = crv(t)
plt.plot(x[:,0], x[:,1], 'r-') # plot curve (in red)
plt.axis('equal')
plt.show()
In [3]:
crv = curve_factory.n_gon(6) # create a sample curve
t0 = crv.start() # parametric starting point
t1 = crv.end() # parametric end point
t = np.linspace(t0, t1, 361) # uniform grid of 361 evaluation points on the parametric domain
x = crv(t)
plt.plot(x[:,0], x[:,1]) # plot curve
dx = [0.1, 0.1] # translation amount
crv.translate(dx) # move the object by 'dx'
x = crv(t)
plt.plot(x[:,0], x[:,1], 'r-') # plot curve (in red)
plt.axis('equal')
plt.show()
Note that translate can also be applied as an operator
In [4]:
crv.translate([1, 2]) # moves object 1 in x-direction, 2 in y-direction
crv += [1,2] # does the exact same thing
crv = crv + [1,2] # same thing
crv_2 = crv + [1,2] # creates a new object crv_2 which is the translated version of crv
crv += (1,2) # translation vector only needs to be array-like (any indexable input will work)
In [5]:
crv = curve_factory.n_gon(6) # create a sample curve
t0 = crv.start() # parametric starting point
t1 = crv.end() # parametric end point
t = np.linspace(t0, t1, 361) # uniform grid of 361 evaluation points on the parametric domain
x = crv(t)
plt.plot(x[:,0], x[:,1]) # plot curve
crv.scale(1.5) # scales the object by a factor of 150%
x = crv(t)
plt.plot(x[:,0], x[:,1], 'r-') # plot curve (in red)
plt.axis('equal')
plt.show()
Scaling is also available as operators
In [6]:
crv.scale(1.5)
crv *= 1.5 # does the exact same thing
crv = crv * 1.5 # same thing
crv_2 = crv * 1.5 # keeps crv unchanged, returns a new object crv_2 which is the scaled version of crv
crv *= (2,1) # doubles the size in x-direction, while leaving the size in y-direction unchanged
In [7]:
curve = curve_factory.n_gon(6)
# for a slightly more inefficient translation operations, we may manipulate the controlpoints one-by-one
for controlpoint in curve:
controlpoint += [1,0]
# alternative way of iterating over the controlpoints of a spline object
for i in range(len(curve)):
curve[i] += [1,0]
print(curve)
In [8]:
curve[0] += [1,0] # this will move the first controlpoint one unit in the x-direction
curve[0,0] += 1 # exact same thing (now moved a total of two)
print(curve)
In [ ]: