Files
Jungfraujoch/image_analysis/CrystalLattice.cpp
2024-10-05 13:14:49 +02:00

52 lines
1.2 KiB
C++

// Copyright (2019-2023) Paul Scherrer Institute
#include <cmath>
#include "CrystalLattice.h"
#define DEG_TO_RAD static_cast<float>(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<float> &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;
}
}