PLaSK library
Loading...
Searching...
No Matches
cuboid.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__GEOMETRY_CUBOID_H
15#define PLASK__GEOMETRY_CUBOID_H
16
21#include "leaf.hpp"
22#include "../math.hpp"
23
24
25namespace plask {
26
32struct PLASK_API RotatedCuboid : public Block<3> {
35
38
39 static const char* NAME;
40
41 protected:
43 double c;
44
46 double s;
47
48 public:
54 DVec trans(double c0, double c1, double c2 = 0.) const { return DVec(c * c0 - s * c1, s * c0 + c * c1, c2); }
55
61 DVec trans(const DVec& vec) const { return trans(vec.c0, vec.c1, vec.c2); }
62
68 DVec itrans(double c0, double c1, double c2 = 0.) const { return DVec(c * c0 + s * c1, -s * c0 + c * c1, c2); }
69
75 DVec itrans(const DVec& vec) const { return itrans(vec.c0, vec.c1, vec.c2); }
76
77 std::string getTypeName() const override;
78
83 double getAngle() const { return 180. / M_PI * atan2(s, c); }
84
89 void setAngle(double angle) {
90 double rot = M_PI / 180. * angle;
91 c = cos(rot);
92 s = sin(rot);
93 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
94 }
95
103 double angle = 0.,
104 const shared_ptr<Material>& material = shared_ptr<Material>())
105 : Block<3>(size, material) {
106 double rot = M_PI / 180. * angle;
107 c = cos(rot);
108 s = sin(rot);
109 }
110
111 explicit RotatedCuboid(double angle) {
112 double rot = M_PI / 180. * angle;
113 c = cos(rot);
114 s = sin(rot);
115 }
116
118 : Block<3>(size, materialTopBottom) {
119 double rot = M_PI / 180. * angle;
120 c = cos(rot);
121 s = sin(rot);
122 }
123
124 explicit RotatedCuboid(const Block<3>& src) : Block<3>(src), c(1), s(0) {}
125
126 explicit RotatedCuboid(const RotatedCuboid& src) : Block<3>(src), c(src.c), s(src.s) {}
127
128 Box getBoundingBox() const override;
129
130 bool contains(const DVec& p) const override;
131
133
134 void addPointsAlongToSet(std::set<double>& points,
135 Primitive<3>::Direction direction,
136 unsigned max_steps,
137 double min_step_size) const override;
138
139 void addLineSegmentsToSet(std::set<typename GeometryObjectD<3>::LineSegment>& segments,
140 unsigned max_steps,
141 double min_step_size) const override;
142
143 void writeXMLAttr(XMLWriter::Element& dest_xml_object, const AxisNames& axes) const override;
144};
145
146shared_ptr<GeometryObject> read_cuboid(GeometryReader& reader);
147
148} // namespace plask
149
150#endif