groups

Link to this snippet:


Download to Code Collector

language: C++
licence: Other

Distance from a point to a line

options: send to code collectorview all nepahwin's snippets
Float_t distance_from_muon(Float_t n_x, Float_t n_y, Float_t n_z,
                           Float_t muon_x, Float_t muon_y, Float_t muon_z,
                           Float_t muon_u, Float_t muon_v, Float_t muon_w) {

  // Calculate the distance of a point (n_x, n_y, n_z) from a line specified
  // by a point (muon_u, muon_v, muon_w) and direction cosines (muon_u, muon_v, muon_w).

  TVector3 ref_point(n_x, n_y, n_z);
  TVector3 line_point(muon_x, muon_y, muon_z);
  TVector3 line_direction_cosines(muon_u, muon_v, muon_w);

  TVector3 v = ref_point - line_point;

  Double_t d = (line_direction_cosines.Cross(v)).Mag()
             / line_direction_cosines.Mag();

  return d;

}