运用python画光刻板版图
第三章 图形类讲解
图形文件夹内包含矩形、任意多边形、环形及扇形。
1、矩形类
新建矩形类只需传入矩形坐标即可,坐标点如下图所示,坐标格式为rect=[x0,x1,y0,y1],若不传入坐标信息则会新建一个空图形。
class Rectangle(Object2D):
def __init__(self, layer = 0,rect=np.zeros(4)):
super().__init__()
self.name = 'Rectangle'
self.layer = layer
self.position = np.array([[rect[0], rect[2]],
[rect[0], rect[3]],
[rect[1], rect[3]],
[rect[1], rect[2]]])
2、多边形类
新建多边形类需要传入多边形各个点的坐标值。
class Polygon(Object2D):
def __init__(self, layer=0,vtx=np.zeros(4),move=[0,0]):
super().__init__()
self.name = 'Polygon'
self.layer = layer
self.position = np.array(vtx)
self.move(move)
3、环形类
新建一个环形类需要输入环形的圆形坐标、半径、厚度、开始角度与结束角度、环形类型(普通环形或光栅环形)、椭圆环形半径(该值若为0表示圆环,不为零表示椭圆环)、组成改换需要的点数。其示意图如下所。新建该环形类时会自动调用draw_ring函数来生成组成环形所需要的点。
class Ring(Object2D):
def __init__(self, x=0, y=0, radius=0, think=0, theta_start=0, theta_stop=0, port_type=0,elliptical=0,number_of_points=100,layer=0):
super().__init__()
self.name = 'Ring'
self.x = x
self.y = y
self.radius = radius
self.think = think
self.theta_start = theta_start
self.theta_stop = theta_stop
self.port_type = port_type
self.elliptical = elliptical
self.position = self.draw_ring(number_of_points)
self.layer = layer
def draw_ring(self, number_of_points):
points = []
self.angle = self.theta_stop - self.theta_start
if self.port_type == 0:
for i in range(number_of_points + 1):
points.append([
self.x + (self.radius + self.think / 2) * np.sin(self.angle * i / number_of_points + self.theta_start),
self.y + (self.radius + self.elliptical / 2 + self.think / 2) * np.cos(
self.angle * i / number_of_points + self.theta_start)])
for i in range(number_of_points + 1):
points.append([
self.x + (self.radius - self.think / 2) * np.sin(-self.angle * i / number_of_points + self.theta_stop),
self.y + (self.radius + self.elliptical / 2 - self.think / 2) * np.cos(
-self.angle * i / number_of_points + self.theta_stop)])
else:
for i in range(number_of_points + 1):
points.append([
self.x + self.radius * np.sin(self.angle * i / number_of_points + self.theta_start) + self.think * np.sin(
(self.theta_start + self.theta_stop) / 2) / 2,
self.y + (self.radius + self.elliptical / 2) * np.cos(
self.angle * i / number_of_points + self.theta_start) + self.think * np.cos(
(self.theta_start + self.theta_stop) / 2) / 2])
for i in range(number_of_points + 1):
points.append([
self.x + self.radius * np.sin(-self.angle * i / number_of_points + self.theta_stop) - self.think * np.sin(
(self.theta_start + self.theta_stop) / 2) / 2,
self.y + (self.radius + self.elliptical / 2) * np.cos(
-self.angle * i / number_of_points + self.theta_stop) - self.think * np.cos(
(self.theta_start + self.theta_stop) / 2) / 2])
return points
4、扇形类
新建扇形类,其参数与环形类的参数大致相当。该类与环形类主要用来绘制光栅结构。
class Sector(Object2D):
def __init__(self, x=0, y=0, radius=0, theta_start=0, theta_stop=0, elliptical=0, layer=0,
number_of_points=100):
super().__init__()
self.name = 'Sector'
self.layer = layer
self.x = x
self.y = y
self.radius = radius
self.theta_start = theta_start
self.theta_stop = theta_stop
self.elliptical = elliptical
self.position = self.draw_sector(number_of_points)
def draw_sector(self, number_of_points):
points = []
self.angle = self.theta_stop - self.theta_start
for i in range(number_of_points + 1):
points.append([self.x + self.radius * np.sin(self.angle * i / number_of_points + self.theta_start),
self.y + (self.radius + self.elliptical / 2) * np.cos(
self.angle * i / number_of_points + self.theta_start)])
points.append([self.x, self.y + self.elliptical / 2])
points.append([self.x, self.y - self.elliptical / 2])
return points
elf.y + self.elliptical / 2])
points.append([self.x, self.y - self.elliptical / 2])
return points