Lumerical Script ------ Draw a three-dimensional quadrangular pyramid(绘制一个三维的四棱台)

81 篇文章 7 订阅 ¥399.90 ¥99.00

Lumerical Script ------ Draw a three-dimensional quadrangular pyramid


所谓四棱台指的就是一个平面二维梯形的延展体。今天我们介绍一下如何在 Lumerical软件中绘制一个四棱台物体。

首先我们需要注意,在Lumerical仿真软件中,对于梯形的绘制仅仅只能在XY面产生,如果想要得到四棱台,那么就需要把在XY平面内产生的提醒沿着Z方向做一个拉伸,因此,如果我们需要进行三维仿真,那么应该选取光线的传播方向为X或者Y方向。

# clear Script Prompt page
clc;
# clear Script Workspace
clear;
# delete all objects
deleteall;

# set the unit, here we use micrometer
um = 1e-6;

# add a polygon
addpoly; 
# set the name of polygon
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是代码实现: ```c++ #include <iostream> #include <cmath> using namespace std; // 定义平面图形的基类 class Plane { public: virtual double area() const = 0; // 求面积的纯虚函数 }; // 定义柱体的基类 class Body { public: virtual double volume() const = 0; // 求体积的纯虚函数 }; // 从虚基类 Plane 派生出具体类 Rectangle(长方形) class Rectangle : virtual public Plane { protected: double width; // 宽 double height; // 高 public: Rectangle(double w, double h) : width(w), height(h) {} double area() const override { // 覆盖基类求面积的函数 return width * height; } }; // 从 Rectangle 派生出具体类 Square(正方形) class Square : public Rectangle { public: Square(double s) : Rectangle(s, s) {} // 正方形的宽和高相等 }; // 从虚基类 Plane 派生出具体类 Circle(圆形) class Circle : virtual public Plane { protected: double radius; // 半径 public: Circle(double r) : radius(r) {} double area() const override { // 覆盖基类求面积的函数 return M_PI * radius * radius; } }; // 从虚基类 Plane 派生出具体类 Triangle(三角形) class Triangle : virtual public Plane { protected: double a; // 边长1 double b; // 边长2 double c; // 边长3 public: Triangle(double x, double y, double z) : a(x), b(y), c(z) {} double area() const override { // 覆盖基类求面积的函数 double p = (a + b + c) / 2; return sqrt(p * (p - a) * (p - b) * (p - c)); } }; // 从具体类 Triangle、Square 和 Circle 派生出 Triangularprism(三棱柱)、Quadrangular棱柱)和 Circularcolumn(圆柱)类 class Triangularprism : public Triangle, public Body { protected: double height; // 高 public: Triangularprism(double x, double y, double z, double h) : Triangle(x, y, z), height(h) {} double volume() const override { // 覆盖基类求体积的函数 return Triangle::area() * height; } }; class Quadrangular : public Rectangle, public Body { protected: double height; // 高 public: Quadrangular(double w, double h, double d) : Rectangle(w, h), height(d) {} double volume() const override { // 覆盖基类求体积的函数 return Rectangle::area() * height; } }; class Circularcolumn : public Circle, public Body { protected: double height; // 高 public: Circularcolumn(double r, double h) : Circle(r), height(h) {} double volume() const override { // 覆盖基类求体积的函数 return Circle::area() * height; } }; int main() { // 构造一个长方形 Rectangle r(3, 4); cout << "长方形的面积为:" << r.area() << endl; // 构造一个正方形 Square s(5); cout << "正方形的面积为:" << s.area() << endl; // 构造一个圆形 Circle c(2); cout << "圆形的面积为:" << c.area() << endl; // 构造一个三角形 Triangle t(3, 4, 5); cout << "三角形的面积为:" << t.area() << endl; // 构造一个三棱柱 Triangularprism tp(3, 4, 5, 6); cout << "三棱柱的体积为:" << tp.volume() << endl; // 构造一个棱柱 Quadrangular q(3, 4, 5); cout << "棱柱的体积为:" << q.volume() << endl; // 构造一个圆柱 Circularcolumn cc(2, 6); cout << "圆柱的体积为:" << cc.volume() << endl; return 0; } ``` 输出结果为: ``` 长方形的面积为:12 正方形的面积为:25 圆形的面积为:12.5664 三角形的面积为:6 三棱柱的体积为:36 棱柱的体积为:60 圆柱的体积为:75.3982 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

勤奋的大熊猫

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

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

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

打赏作者

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

抵扣说明:

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

余额充值