File: Polyhedra.h

package info (click to toggle)
bornagain 23.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,948 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (414 lines) | stat: -rw-r--r-- 12,385 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/HardParticle/Polyhedra.h
//! @brief     Defines class Box.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRA_H
#define BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRA_H

#include "Sample/HardParticle/IFormfactorPolyhedron.h"
#include "Sample/HardParticle/IFormfactorPrism.h"

//  ************************************************************************************************
//  Prisms
//  ************************************************************************************************

//! A rectangular prism (parallelepiped).

class Box : public IFormfactorPrism {
public:
    Box(double length, double width, double height);
    Box(std::vector<double> P);

#ifndef SWIG
    Box* clone() const override { return new Box(m_length, m_width, m_height); }
#endif // SWIG

    std::string className() const final { return "Box"; }

    std::vector<ParaMeta> parDefs() const final
    {
        return {{"Length", "nm"}, {"Width", "nm"}, {"Height", "nm"}};
    }

    double length() const { return m_length; }
    double width() const { return m_width; }
    double height() const override { return m_height; }

    bool contains(const R3& position) const override;

private:
    const double& m_length;
    const double& m_width;
    const double& m_height;
};

//! A prism based on an equilateral triangle.

class Prism3 : public IFormfactorPrism {
public:
    Prism3(double base_edge, double height);
    Prism3(std::vector<double> P);

#ifndef SWIG
    Prism3* clone() const override { return new Prism3(m_base_edge, m_height); }
#endif // SWIG

    std::string className() const final { return "Prism3"; }
    std::vector<ParaMeta> parDefs() const final { return {{"BaseEdge", "nm"}, {"Height", "nm"}}; }

    double baseEdge() const { return m_base_edge; }
    double height() const override { return m_height; }

    bool contains(const R3& position) const override;

private:
    const double& m_base_edge;
    const double& m_height;
};

//! A prism based on a regular hexagonal.

class Prism6 : public IFormfactorPrism {
public:
    Prism6(double base_edge, double height);
    Prism6(std::vector<double> P);

#ifndef SWIG
    Prism6* clone() const override { return new Prism6(m_base_edge, m_height); }
#endif // SWIG

    std::string className() const final { return "Prism6"; }
    std::vector<ParaMeta> parDefs() const final { return {{"BaseEdge", "nm"}, {"Height", "nm"}}; }

    double baseEdge() const { return m_base_edge; }
    double height() const override { return m_height; }

    bool contains(const R3& position) const override;

private:
    const double& m_base_edge;
    const double& m_height;
};

//  ************************************************************************************************
//  Platonic solids
//  ************************************************************************************************

//! A frustum with equilateral trigonal base.

class PlatonicTetrahedron : public IFormfactorPolyhedron {
public:
    PlatonicTetrahedron(double edge);
    PlatonicTetrahedron(std::vector<double> P);

#ifndef SWIG
    PlatonicTetrahedron* clone() const override { return new PlatonicTetrahedron(m_edge); }
#endif // SWIG

    std::string className() const final { return "PlatonicTetrahedron"; }
    std::vector<ParaMeta> parDefs() const final { return {{"Edge", "nm"}}; }

    double edge() const { return m_edge; }
    double height() const { return sqrt(2. / 3) * m_edge; }

    bool contains(const R3& position) const override;

private:
    const double& m_edge;
};

//! A truncated bifrustum with quadratic base.

class PlatonicOctahedron : public IFormfactorPolyhedron {
public:
    PlatonicOctahedron(double edge);
    PlatonicOctahedron(std::vector<double> P);

#ifndef SWIG
    PlatonicOctahedron* clone() const override { return new PlatonicOctahedron(m_edge); }
#endif // SWIG

    std::string className() const final { return "PlatonicOctahedron"; }
    std::vector<ParaMeta> parDefs() const final { return {{"Edge", "nm"}}; }

    double edge() const { return m_edge; }
    double height() const { return sqrt(1 / 2.) * m_edge; }

    bool contains(const R3& position) const override;

private:
    const double& m_edge;
};

//! A regular dodecahedron.

class Dodecahedron : public IFormfactorPolyhedron {
public:
    Dodecahedron(double edge);
    Dodecahedron(std::vector<double> P);

#ifndef SWIG
    Dodecahedron* clone() const override { return new Dodecahedron(m_edge); }
#endif // SWIG

    std::string className() const final { return "Dodecahedron"; }
    std::vector<ParaMeta> parDefs() const final { return {{"Edge", "nm"}}; }

    double edge() const { return m_edge; }

    bool contains(const R3& position) const override;

private:
    const double& m_edge;
};

//! A regular icosahedron.

class Icosahedron : public IFormfactorPolyhedron {
public:
    Icosahedron(double edge);
    Icosahedron(std::vector<double> P);

#ifndef SWIG
    Icosahedron* clone() const override { return new Icosahedron(m_edge); }
#endif // SWIG

    std::string className() const final { return "Icosahedron"; }
    std::vector<ParaMeta> parDefs() const final { return {{"Edge", "nm"}}; }

    double edge() const { return m_edge; }

    bool contains(const R3& position) const override;

private:
    const double& m_edge;
};

//  ************************************************************************************************
//  Pyramids
//  ************************************************************************************************

//! A frustum (truncated pyramid) with rectangular base.

class Pyramid2 : public IFormfactorPolyhedron {
public:
    Pyramid2(double length, double width, double height, double alpha);
    Pyramid2(std::vector<double> P);

#ifndef SWIG
    Pyramid2* clone() const override { return new Pyramid2(m_length, m_width, m_height, m_alpha); }
#endif // SWIG

    std::string className() const final { return "Pyramid2"; }
    std::vector<ParaMeta> parDefs() const final
    {
        return {{"Length", "nm"}, {"Width", "nm"}, {"Height", "nm"}, {"Alpha", "rad"}};
    }

    double length() const { return m_length; }
    double width() const { return m_width; }
    double height() const { return m_height; }
    double alpha() const { return m_alpha; }

    bool contains(const R3& position) const override;

private:
    const double& m_length;
    const double& m_width;
    const double& m_height;
    const double& m_alpha;
};

//! A frustum with equilateral trigonal base.

class Pyramid3 : public IFormfactorPolyhedron {
public:
    Pyramid3(double base_edge, double height, double alpha);
    Pyramid3(std::vector<double> P);

#ifndef SWIG
    Pyramid3* clone() const override { return new Pyramid3(m_base_edge, m_height, m_alpha); }
#endif // SWIG

    std::string className() const final { return "Pyramid3"; }
    std::vector<ParaMeta> parDefs() const final
    {
        return {{"BaseEdge", "nm"}, {"Height", "nm"}, {"Alpha", "rad"}};
    }

    double baseEdge() const { return m_base_edge; }
    double height() const { return m_height; }
    double alpha() const { return m_alpha; }

    bool contains(const R3& position) const override;

private:
    const double& m_base_edge;
    const double& m_height;
    const double& m_alpha;
};

//! A frustum with a quadratic base.

class Pyramid4 : public IFormfactorPolyhedron {
public:
    Pyramid4(double base_edge, double height, double alpha);
    Pyramid4(std::vector<double> P);

#ifndef SWIG
    Pyramid4* clone() const override { return new Pyramid4(m_base_edge, m_height, m_alpha); }
#endif // SWIG

    std::string className() const final { return "Pyramid4"; }
    std::vector<ParaMeta> parDefs() const final
    {
        return {{"BaseEdge", "nm"}, {"Height", "nm"}, {"Alpha", "rad"}};
    }

    double height() const { return m_height; }
    double baseEdge() const { return m_base_edge; }
    double alpha() const { return m_alpha; }

    bool contains(const R3& position) const override;

private:
    const double& m_base_edge;
    const double& m_height;
    const double& m_alpha;
};

//! A frustum (truncated pyramid) with regular hexagonal base.

class Pyramid6 : public IFormfactorPolyhedron {
public:
    Pyramid6(double base_edge, double height, double alpha);
    Pyramid6(std::vector<double> P);

#ifndef SWIG
    Pyramid6* clone() const override { return new Pyramid6(m_base_edge, m_height, m_alpha); }
#endif // SWIG

    std::string className() const final { return "Pyramid6"; }
    std::vector<ParaMeta> parDefs() const final
    {
        return {{"BaseEdge", "nm"}, {"Height", "nm"}, {"Alpha", "rad"}};
    }

    double baseEdge() const { return m_base_edge; }
    double height() const { return m_height; }
    double alpha() const { return m_alpha; }

    bool contains(const R3& position) const override;

private:
    const double& m_base_edge;
    const double& m_height;
    const double& m_alpha;
};

//! A truncated bifrustum with quadratic base.

class Bipyramid4 : public IFormfactorPolyhedron {
public:
    Bipyramid4(double length, double base_height, double height_ratio, double alpha);
    Bipyramid4(std::vector<double> P);

#ifndef SWIG
    Bipyramid4* clone() const override
    {
        return new Bipyramid4(m_length, m_base_height, m_height_ratio, m_alpha);
    }
#endif // SWIG

    std::string className() const final { return "Bipyramid4"; }
    std::vector<ParaMeta> parDefs() const final
    {
        return {{"Length", "nm"}, {"Height", "nm"}, {"HeightRatio", ""}, {"Alpha", "rad"}};
    }
    double length() const { return m_length; }
    double base_height() const { return m_base_height; }
    double heightRatio() const { return m_height_ratio; }
    double alpha() const { return m_alpha; }
    double height() const { return (1 + m_height_ratio) * m_base_height; }

    bool contains(const R3& position) const override;

private:
    const double& m_length;
    const double& m_base_height;
    const double& m_height_ratio;
    const double& m_alpha;
};

//  ************************************************************************************************
//  Others
//  ************************************************************************************************

//! A cube, with truncation of all edges and corners, as in Croset (2017) Fig 7

class CantellatedCube : public IFormfactorPolyhedron {
public:
    CantellatedCube(double length, double removed_length);
    CantellatedCube(std::vector<double> P);

#ifndef SWIG
    CantellatedCube* clone() const override
    {
        return new CantellatedCube(m_length, m_removed_length);
    }
#endif // SWIG

    std::string className() const final { return "CantellatedCube"; }
    std::vector<ParaMeta> parDefs() const final
    {
        return {{"Length", "nm"}, {"RemovedLength", "nm"}};
    }

    double length() const { return m_length; }
    double removedLength() const { return m_removed_length; }

    bool contains(const R3& position) const override;

private:
    const double& m_length;
    const double& m_removed_length;
};

//! A cube, with tetrahedral truncation of all corners

class TruncatedCube : public IFormfactorPolyhedron {
public:
    TruncatedCube(double length, double removed_length);
    TruncatedCube(std::vector<double> P);

#ifndef SWIG
    TruncatedCube* clone() const override { return new TruncatedCube(m_length, m_removed_length); }
#endif // SWIG

    std::string className() const final { return "TruncatedCube"; }
    std::vector<ParaMeta> parDefs() const final
    {
        return {{"Length", "nm"}, {"RemovedLength", "nm"}};
    }

    double length() const { return m_length; }
    double removedLength() const { return m_removed_length; }

    bool contains(const R3& position) const override;

private:
    const double& m_length;
    const double& m_removed_length;
};

#endif // BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRA_H