// Copyright (2019-2023) Paul Scherrer Institute #include #include "CrystalLattice.h" #define DEG_TO_RAD static_cast(M_PI/180.0) CrystalLattice::CrystalLattice() {} CrystalLattice::CrystalLattice(const UnitCell &cell) { vec[0] = {cell.a, 0, 0}; vec[1] = {cell.b * cosf(cell.gamma * DEG_TO_RAD), cell.b * sinf(cell.gamma * DEG_TO_RAD), 0}; float cx = cell.c * cosf(cell.beta * DEG_TO_RAD); float cy = cell.c * (cosf(cell.alpha * DEG_TO_RAD) - cosf(cell.beta * DEG_TO_RAD) * cosf(cell.gamma * DEG_TO_RAD)) / sinf(cell.gamma * DEG_TO_RAD); vec[2] = {cx, cy, sqrtf(cell.c*cell.c-cx*cx-cy*cy)}; } Coord &CrystalLattice::Vec0() { return vec[0]; } Coord &CrystalLattice::Vec1() { return vec[1]; } Coord &CrystalLattice::Vec2() { return vec[2]; } const Coord &CrystalLattice::Vec0() const { return vec[0]; } const Coord &CrystalLattice::Vec1() const { return vec[1]; } const Coord &CrystalLattice::Vec2() const { return vec[2]; } void CrystalLattice::Save(std::vector &output) { output.resize(9); for (int i = 0; i < 3; i++) { output[3 * i + 0] = vec[i].x; output[3 * i + 1] = vec[i].y; output[3 * i + 2] = vec[i].z; } }