运用python画光刻板版图-3图形类讲解

本文介绍了如何使用Python创建图形类,包括矩形、多边形、环形和扇形。每个类都详细说明了构造函数的参数,如坐标、半径、角度等,并展示了如何通过这些参数生成各种图形。环形类还包括了绘制光栅环形的功能,而扇形类主要用于绘制光栅结构。
摘要由CSDN通过智能技术生成

运用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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

skyer_lhb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值