Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
Vec.hh File Reference
#include <cmath>
#include <iostream>
#include <sstream>
#include "Rtypes.h"

Go to the source code of this file.

Classes

struct  Vec
 The Vec class is a straightforward 3-d vector, which also works in pyroot. More...
 

Functions

std::ostream & operator<< (std::ostream &out, const Vec &v)
 Write vector to output stream.
 
std::istream & operator>> (std::istream &in, Vec &v)
 Read vector from input stream.
 
double cos_angle_between (const Vec &a, const Vec &b)
 Get cosine of space angle between two vectors.
 
double angle_between (const Vec &a, const Vec &b)
 Get space angle between two vectors.
 
Vec operator+ (const Vec &a, const Vec &b)
 Add two vectors.
 
Vec operator- (const Vec &a, const Vec &b)
 Subtract two vectors.
 
Vec operator* (double a, const Vec &v)
 Multiply vector.
 
Vec operator* (const Vec &v, double a)
 Multiply vector.
 
Vec operator/ (const Vec &v, double a)
 Divide vector.
 

Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream & out,
const Vec & v )
inline

Write vector to output stream.

Parameters
outoutput stream
vvector
Returns
output stream

Definition at line 284 of file Vec.hh.

285{
286 out << v.x << " " << v.y << " " << v.z << " ";
287 return out;
288}
double z
Definition Vec.hh:14
double x
Definition Vec.hh:14
double y
Definition Vec.hh:14

◆ operator>>()

std::istream & operator>> ( std::istream & in,
Vec & v )
inline

Read vector from input stream.

Parameters
ininput stream
vvector
Returns
input stream

Definition at line 297 of file Vec.hh.

298{
299 in >> v.x >> v.y >> v.z ; return in;
300}

◆ cos_angle_between()

double cos_angle_between ( const Vec & a,
const Vec & b )
inline

Get cosine of space angle between two vectors.

Parameters
afirst vector
bsecond vector
Returns
cosine

Definition at line 309 of file Vec.hh.

310{
311 const double n = a.len() * b.len();
312 return a.dot(b) / n;
313}
const double a
const int n
Definition JPolint.hh:791
double len() const
Get length.
Definition Vec.hh:145

◆ angle_between()

double angle_between ( const Vec & a,
const Vec & b )
inline

Get space angle between two vectors.

Parameters
afirst vector
bsecond vector
Returns
angle [rad]

Definition at line 322 of file Vec.hh.

323{
324 double c = cos_angle_between( a, b );
325 if ( c < -1 ) return M_PI;
326 if ( c > 1 ) return 0;
327 return acos( c );
328}
double cos_angle_between(const Vec &a, const Vec &b)
Get cosine of space angle between two vectors.
Definition Vec.hh:309

◆ operator+()

Vec operator+ ( const Vec & a,
const Vec & b )
inline

Add two vectors.

Parameters
afirst vector
bsecond vector
Returns
vector

Definition at line 337 of file Vec.hh.

337{ Vec r(a); return r+=b;}
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13

◆ operator-()

Vec operator- ( const Vec & a,
const Vec & b )
inline

Subtract two vectors.

Parameters
afirst vector
bsecond vector
Returns
vector

Definition at line 346 of file Vec.hh.

346{ Vec r(a); return r-=b;}

◆ operator*() [1/2]

Vec operator* ( double a,
const Vec & v )
inline

Multiply vector.

Parameters
afactor
vvector
Returns
vector

Definition at line 355 of file Vec.hh.

355{ return Vec(a*v.x,a*v.y,a*v.z);}

◆ operator*() [2/2]

Vec operator* ( const Vec & v,
double a )
inline

Multiply vector.

Parameters
vvector
afactor
Returns
vector

Definition at line 364 of file Vec.hh.

364{ return Vec(a*v.x,a*v.y,a*v.z);}

◆ operator/()

Vec operator/ ( const Vec & v,
double a )
inline

Divide vector.

Parameters
vvector
afactor
Returns
vector

Definition at line 373 of file Vec.hh.

373{ return Vec(v.x/a,v.y/a,v.z/a);}