File: Cuboctahedron.cpp

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 (69 lines) | stat: -rw-r--r-- 2,091 bytes parent folder | download
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
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Img3D/Mesh/Cuboctahedron.cpp
//! @brief     Implements utility functions in ba3d namespace.
//!
//! @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)
//
//  ************************************************************************************************

#include "Base/Util/Assert.h"
#include "Img3D/Model/Geometry.h"
#include <numbers>

using std::numbers::pi;

namespace Img3D {

Geometry::Mesh Geometry::meshBipyramid4(float rH, float alpha, float H)
{ // t/D

    // alpha is the angle between the common square interface and one of the side faces (alpha for
    // both the two truncated pyramids is the same)

    // H here is the normalized height of the cuboctahedron i.e. H/L (see particles.cpp)

    ASSERT(alpha <= float((pi / 2)));
    ASSERT(rH >= 0);

    float const D = .5f, t = tanf(float((pi / 2)) - alpha);
    float const Db = D - t * H, Dt = D - t * rH * H;

    Vertices vs_;
    vs_.reserve(12);
    float z[] = {0, H, H * (rH + 1)},
          d[] = {Db, D, Dt}; // keep bottom of the cuboctahedron in z=0 plane
    for (int i = 0; i < 3; ++i)
        for (int x : {-1, +1})
            for (int y : {-1, +1}) {
                float di = d[i];
                vs_.append(F3(x * di, y * di, z[i]));
            }

    ASSERT(12 == vs_.count());

    Vertices vs;
    vs.reserve(60);

    vs.addQuad(vs_, 0, 1, 3, 2);
    vs.addQuad(vs_, 8, 10, 11, 9);
    vs.addQuad(vs_, 0, 4, 5, 1);
    vs.addQuad(vs_, 1, 5, 7, 3);
    vs.addQuad(vs_, 3, 7, 6, 2);
    vs.addQuad(vs_, 2, 6, 4, 0);
    vs.addQuad(vs_, 4, 8, 9, 5);
    vs.addQuad(vs_, 5, 9, 11, 7);
    vs.addQuad(vs_, 7, 11, 10, 6);
    vs.addQuad(vs_, 6, 10, 8, 4);

    ASSERT(60 == vs.count());

    return makeMesh(vs);
}

} // namespace Img3D