projection plane on local coordinates

This commit is contained in:
AndreaRigoni
2026-03-19 09:52:19 +00:00
parent ca2223e04c
commit c8eec163a6
3 changed files with 42 additions and 3 deletions

View File

@@ -6,8 +6,10 @@ namespace uLib {
MuonEvent DetectorChamber::ProjectMuonEvent(const MuonEvent &muon) const {
MuonEvent projectedMuon = muon;
HPoint3f P = m_ProjectionPlane.origin;
HVector3f N = m_ProjectionPlane.direction;
// Transform the local projection plane to world coordinates
HLine3f worldPlane = this->GetWorldProjectionPlane();
HPoint3f P = worldPlane.origin;
HVector3f N = worldPlane.direction;
HPoint3f X_in = muon.LineIn().origin;
HPoint3f X_out = muon.LineOut().origin;

View File

@@ -45,12 +45,30 @@ class DetectorChamber : public ContainerBox {
public:
DetectorChamber() : BaseClass() {
m_ProjectionPlane.origin = HPoint3f(0, 0, 0);
m_ProjectionPlane.direction = HVector3f(0, 0, 1);
}
DetectorChamber(const Vector3f &size) : BaseClass(size) {
m_ProjectionPlane.origin = HPoint3f(0, 0, 0);
m_ProjectionPlane.direction = HVector3f(0, 0, 1);
}
// set the plane where muons hit is projected
// to be represented with a direction vector
// coordinates are local to the container box
void SetProjectionPlane(const HLine3f &normal) { m_ProjectionPlane = normal; }
const HLine3f &GetProjectionPlane() const { return m_ProjectionPlane; }
HLine3f GetWorldProjectionPlane() const {
HLine3f worldPlane;
Matrix4f M = this->GetWorldMatrix();
worldPlane.origin = M * m_ProjectionPlane.origin;
worldPlane.direction = M * m_ProjectionPlane.direction;
return worldPlane;
}
MuonEvent ProjectMuonEvent(const MuonEvent &muon) const;
private:

View File

@@ -116,5 +116,24 @@ int main() {
bool posOk3 = (projected.LineIn().origin - expectedPos).norm() < 1e-5;
TEST1(posOk3);
// Test Case 4: Transformed DetectorChamber
DetectorChamber chamber2;
chamber2.SetPosition(Vector3f(0, 0, 100)); // Move chamber to z=100
// chamber2.GetProjectionPlane has default origin (0,0,0) and direction (0,0,1)
// In world coordinates, this plane is at z = 100 + 0 = 100.
muon.LineIn().origin = HPoint3f(50, 60, 50); // dist to world plane (z=100) is 50
muon.LineOut().origin = HPoint3f(50, 60, 200); // dist to world plane (z=100) is 100
projected = chamber2.ProjectMuonEvent(muon);
expectedPos = HPoint3f(50, 60, 100);
std::cout << "\nTest Case 4: Transformed DetectorChamber (active world matrix)" << std::endl;
std::cout << "Projected Position: " << projected.LineIn().origin.transpose() << std::endl;
std::cout << "Expected Position: " << expectedPos.transpose() << std::endl;
bool posOk4 = (projected.LineIn().origin - expectedPos).norm() < 1e-5;
TEST1(posOk4);
END_TESTING;
}