line.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 #ifndef __line_hpp__
23 #define __line_hpp__
24 
25 #include "types.hpp"
26 #include "typeInfo.hpp"
27 
28 namespace pFlow
29 {
30 
31 
32 class dictionary;
33 
34 
35 // pLine
36 class line
37 {
38 protected:
39 
40  // point 1
42 
43  // vector pointing from 1 to 2
45 
46 public:
47 
48  TypeInfoNV("line");
49 
52  line()
53  {}
54 
56  line(const realx3 &lp1, const realx3 &lp2);
57 
59  line(const dictionary& dict);
60 
62  line(const line& src) = default;
63 
65  line(line&& src) = default;
66 
68  line& operator = (const line&) = default;
69 
71  line& operator = (line&&) = default;
72 
73 
75 
76  // set two points of line
78  void set(const realx3 &lp1, const realx3 &lp2)
79  {
80  v21_ = lp2 - lp1;
81  p1_ = lp1;
82  }
83 
84  // return point 1
86  realx3 point1()const { return p1_; }
87 
88  // return point 2
90  realx3 point2()const { return point(1.0); }
91 
92  // get a point on the line based on input 0<= t <= 1
94  realx3 point(real t)const { return v21_ * t + p1_; }
95 
96  // length of line
98  real length()const { return pFlow::length(v21_); }
99 
100  // get unit vector of the line direction vector
102  realx3 unitVector() const{ return normalize(v21_); }
103 
104  // return the projected point of point p on line
106  realx3 projectPoint(const realx3 &p) const
107  {
108  return point(projectNormalizedLength(p));
109  }
110 
111  // calculates the normalized distance between projected p and p1
114  {
115  realx3 w = p - p1_;
116  return dot(w,v21_) / dot(v21_,v21_);
117  }
118 
120  FUNCTION_H
121  bool read(const dictionary& dict);
122 
123  FUNCTION_H
124  bool write(dictionary& ditc) const;
125 
126  FUNCTION_H
127  bool read(iIstream& is);
128 
129  FUNCTION_H
130  bool write(iOstream& os)const;
131 
132 
133 };
134 
135 
136 }
137 
138 
139 #endif //
normalize
INLINE_FUNCTION_HD triple< T > normalize(const triple< T > &v1)
pFlow::line::TypeInfoNV
TypeInfoNV("line")
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::line
Definition: line.hpp:36
types.hpp
pFlow::line::write
FUNCTION_H bool write(dictionary &ditc) const
Definition: line.cpp:61
pFlow::line::set
INLINE_FUNCTION_HD void set(const realx3 &lp1, const realx3 &lp2)
Definition: line.hpp:78
pFlow::line::line
FUNCTION_HD line()
Definition: line.hpp:52
pFlow
Definition: demComponent.hpp:28
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
pFlow::line::read
FUNCTION_H bool read(const dictionary &dict)
Definition: line.cpp:50
dot
INLINE_FUNCTION_HD T dot(const quadruple< T > &oprnd1, const quadruple< T > &oprnd2)
pFlow::line::projectPoint
INLINE_FUNCTION_HD realx3 projectPoint(const realx3 &p) const
Definition: line.hpp:106
pFlow::iIstream
Definition: iIstream.hpp:33
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::line::point2
INLINE_FUNCTION_HD realx3 point2() const
Definition: line.hpp:90
pFlow::line::projectNormalizedLength
INLINE_FUNCTION_HD real projectNormalizedLength(realx3 p) const
Definition: line.hpp:113
pFlow::line::point
INLINE_FUNCTION_HD realx3 point(real t) const
Definition: line.hpp:94
pFlow::line::length
INLINE_FUNCTION_HD real length() const
Definition: line.hpp:98
FUNCTION_HD
#define FUNCTION_HD
Definition: pFlowMacros.hpp:57
pFlow::line::operator=
FUNCTION_HD line & operator=(const line &)=default
pFlow::line::point1
INLINE_FUNCTION_HD realx3 point1() const
Definition: line.hpp:86
pFlow::line::p1_
realx3 p1_
Definition: line.hpp:41
typeInfo.hpp
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::line::unitVector
INLINE_FUNCTION_HD realx3 unitVector() const
Definition: line.hpp:102
pFlow::triple< real >
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::line::v21_
realx3 v21_
Definition: line.hpp:44