www.cemf.ir
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 realx3 &v21, const realx3 &p1, bool)
60  :
61  v21_(v21),
62  p1_(p1)
63  {}
64 
65 
67  line(const dictionary& dict);
68 
70  line(const line& src) = default;
71 
73  line(line&& src) = default;
74 
76  line& operator = (const line&) = default;
77 
79  line& operator = (line&&) = default;
80 
81 
83 
84  // set two points of line
86  void set(const realx3 &lp1, const realx3 &lp2)
87  {
88  v21_ = lp2 - lp1;
89  p1_ = lp1;
90  }
91 
92  // return point 1
94  realx3 point1()const { return p1_; }
95 
96  // return point 2
98  realx3 point2()const { return point(1.0); }
99 
100  // get a point on the line based on input 0<= t <= 1
102  realx3 point(real t)const { return v21_ * t + p1_; }
103 
104  // length of line
106  real length()const { return pFlow::length(v21_); }
107 
108  // get unit vector of the line direction vector
110  realx3 unitVector() const{ return normalize(v21_); }
111 
112  // return the projected point of point p on line
114  realx3 projectPoint(const realx3 &p) const
115  {
116  return point(projectNormalizedLength(p));
117  }
118 
119  // calculates the normalized distance between projected p and p1
122  {
123  realx3 w = p - p1_;
124  return dot(w,v21_) / dot(v21_,v21_);
125  }
126 
128  FUNCTION_H
129  bool read(const dictionary& dict);
130 
131  FUNCTION_H
132  bool write(dictionary& ditc) const;
133 
134  FUNCTION_H
135  bool read(iIstream& is);
136 
137  FUNCTION_H
138  bool write(iOstream& os)const;
139 
140 
141 };
142 
143 
144 }
145 
146 
147 #endif //
normalize
INLINE_FUNCTION_HD triple< T > normalize(const triple< T > &v1)
pFlow::line::TypeInfoNV
TypeInfoNV("line")
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::line
Definition: line.hpp:36
types.hpp
pFlow::line::write
FUNCTION_H bool write(dictionary &ditc) const
Definition: line.cpp:61
pFlow::line::line
INLINE_FUNCTION_HD line(const realx3 &v21, const realx3 &p1, bool)
Definition: line.hpp:59
pFlow::line::set
INLINE_FUNCTION_HD void set(const realx3 &lp1, const realx3 &lp2)
Definition: line.hpp:86
pFlow::line::line
FUNCTION_HD line()
Definition: line.hpp:52
pFlow
Definition: demGeometry.hpp:27
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:62
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::operator=
INLINE_FUNCTION_HD line & operator=(const line &)=default
pFlow::line::projectPoint
INLINE_FUNCTION_HD realx3 projectPoint(const realx3 &p) const
Definition: line.hpp:114
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::line::point2
INLINE_FUNCTION_HD realx3 point2() const
Definition: line.hpp:98
pFlow::line::projectNormalizedLength
INLINE_FUNCTION_HD real projectNormalizedLength(realx3 p) const
Definition: line.hpp:121
pFlow::line::point
INLINE_FUNCTION_HD realx3 point(real t) const
Definition: line.hpp:102
pFlow::line::length
INLINE_FUNCTION_HD real length() const
Definition: line.hpp:106
FUNCTION_HD
#define FUNCTION_HD
Definition: pFlowMacros.hpp:61
pFlow::line::point1
INLINE_FUNCTION_HD realx3 point1() const
Definition: line.hpp:94
pFlow::line::p1_
realx3 p1_
Definition: line.hpp:41
typeInfo.hpp
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::line::unitVector
INLINE_FUNCTION_HD realx3 unitVector() const
Definition: line.hpp:110
pFlow::triple< real >
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67
pFlow::line::v21_
realx3 v21_
Definition: line.hpp:44