Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
include/CGAL/SimpleCartesian/VectorS3.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: VectorS3.h,v 1.3 2008/12/06 08:43:27 mtcampbe Exp $
24 
25 #ifndef CGAL_OPT_SIMPLE_CARTESIAN_VECTOR_3_H
26 #define CGAL_OPT_SIMPLE_CARTESIAN_VECTOR_3_H
27 
29 
30 template < class FT >
31 class VectorS3 {
32 public:
33  typedef VectorS3<FT> Self;
36 
37  VectorS3() {}
38  // VectorS3(const Self &v); // use default copy
39  VectorS3(const Null_vector &) : _x(0), _y(0), _z(0) {}
40  VectorS3(const FT &hx, const FT &hy, const FT& hz, const FT &hw)
41  : _x(hx/hw), _y(hy/hw), _z(hz/hw) {}
42  VectorS3(const FT &x, const FT &y, const FT &z) : _x(x), _y(y), _z(z) {}
43  ~VectorS3() {}
44 
45  Self &operator=(const Self &v) {
46  _x=v._x; _y=v._y; _z=v._z;
47  return *this;
48  }
49 
50  bool operator==(const Self &v) const
51  { return _x==v._x && _y==v._y && _z==v._z; }
52  bool operator==(const Null_vector &) const
53  { return _x==FT(0) && _y==FT(0) && _z==FT(0); }
54  bool operator!=(const Null_vector &) const
55  { return _x!=FT(0) || _y!=FT(0) || _z!=FT(0); }
56 
57  int id() const { return (int)this; }
58 
59  FT hx() const { return _x; }
60  FT hy() const { return _y; }
61  FT hz() const { return _z; }
62  FT hw() const { return FT(1); }
63  FT homogeneous(int i) const { return (i == 3) ? FT(1) : cartesian(i); }
64 
65  const FT& x() const { return _x; }
66  const FT& y() const { return _y; }
67  const FT& z() const { return _z; }
68  FT& x() { return _x; }
69  FT& y() { return _y; }
70  FT& z() { return _z; }
71 
72  const FT& cartesian(int i) const {
73  CGAL_kernel_precondition( i >= 0 && i <= 2 );
74  return (i==0) ? x() :
75  (i==1) ? y() : z() ;
76  }
77 
78  FT& cartesian(int i) {
79  CGAL_kernel_precondition( i >= 0 && i <= 2 );
80  return (i==0) ? x() :
81  (i==1) ? y() : z() ;
82  }
83 
84  FT& operator[](int i) { return cartesian(i); }
85  const FT& operator[](int i) const { return cartesian(i); }
86 
87  int dimension() const { return 3; }
88 
89  Self operator+(const Self &v) const
90  { return Self(_x + v._x, _y + v._y, _z + v._z); }
91  Self operator-(const Self &v) const
92  { return Self(_x - v._x, _y - v._y, _z - v._z); }
93  Self operator-(const Null_vector&) const { return *this; }
94  Self operator-() const { return Self(-_x, -_y, -_z); }
95 
96  Self& operator+=(const Self &v) {
97  _x += v._x; _y+=v._y; _z+=v._z;
98  return *this;
99  }
100  Self& operator-=(const Self &v) {
101  _x -= v._x; _y-=v._y; _z-=v._z;
102  return *this;
103  }
104 
105  FT operator*(const Self &v) const
106  { return _x * v._x + _y * v._y + _z*v._z; }
107  Self operator/(const FT &c) const { return Self( _x/c, _y/c, _z/c); }
108 
109  Self& operator*=(const FT c)
110  { _x *= c; _y *=c; _z *= c; return *this; }
111  Self& operator/=(const FT c)
112  { _x /= c; _y /=c; _z /= c; return *this; }
113 
115  { _x *= v._x; _y *=v._y; _z *=v._z; return *this; }
116  Self& operator/=(const Self &v)
117  { _x /= v._x; _y /=v._y; _z /=v._z; return *this; }
118 
120  { return t.transform(*this); }
121 
122  friend class DirectionS3<FT>;
123  const Direction& direction() const
124  { return reinterpret_cast<const Direction&>(*this); }
125 
126  FT squared_norm() const { return _x*_x+_y*_y+_z*_z; }
127 protected:
128  FT _x,_y,_z;
129 };
130 
131 template < class FT >
132 inline
134 operator*(const FT& c, const VectorS3<FT>& w)
135 { return VectorS3<FT>( c* w.x(), c * w.y(), c * w.z()) ; }
136 
137 template < class FT >
140 {
141  return VectorS3<FT>( v.y() * w.z() - v.z() * w.y() ,
142  v.z() * w.x() - v.x() * w.z() ,
143  v.x() * w.y() - v.y() * w.x() );
144 }
145 
146 template < class FT >
147 std::ostream &operator<<(std::ostream &os, const VectorS3<FT> &v)
148 {
149  switch(os.iword(IO::mode)) {
150  case IO::ASCII :
151  return os << v.x() << ' ' << v.y() << ' ' << v.z();
152  case IO::BINARY :
153  write(os, v.x());
154  write(os, v.y());
155  write(os, v.z());
156  return os;
157  default:
158  os << "VectorS3(" << v.x() << ", " << v.y() << ", " << v.z() << ")";
159  return os;
160  }
161 }
162 
163 template < class FT >
164 std::istream &operator>>(std::istream &is, VectorS3<FT> &v)
165 {
166  switch(is.iword(IO::mode)) {
167  case IO::ASCII :
168  is >> v.x() >> v.y() >> v.z();
169  break;
170  case IO::BINARY :
171  read(is, v.x());
172  read(is, v.y());
173  read(is, v.z());
174  break;
175  default:
176  std::cerr << "\nStream must be in ascii or binary mode\n";
177  break;
178  }
179  return is;
180 }
181 
183 
184 #endif // CGAL_OPT_SIMPLE_CARTESIAN_VECTOR_3_H
185 
186 
187 
188 
189 
190 
Self operator/(const FT &c) const
Vector_3< T > operator*(T t, const Vector_3< T > &v)
Definition: mapbasic.h:139
Self operator+(const Self &v) const
Self transform(const Aff_transformation &t) const
bool operator==(const Null_vector &) const
bool operator==(const Self &v) const
Self operator-(const Self &v) const
VectorS3(const Null_vector &)
VectorS3(const FT &hx, const FT &hy, const FT &hz, const FT &hw)
const FT & operator[](int i) const
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
Definition: io.h:64
Self & operator=(const Self &v)
const FT & cartesian(int i) const
VectorS3< FT > cross_product(const VectorS3< FT > &v, const VectorS3< FT > &w)
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
VectorS3(const FT &x, const FT &y, const FT &z)
Aff_transformationS3< FT > Aff_transformation
blockLoc i
Definition: read.cpp:79
const Direction & direction() const
PointS3< FT > transform(const PointS3< FT > &p) const
static int mode
Definition: io.h:63
Definition: io.h:64
Self operator-(const Null_vector &) const
bool operator!=(const Null_vector &) const
Self & operator-=(const Self &v)
Self & operator+=(const Self &v)
const FT & cartesian(int i) const
void read(std::istream &is, T &t, const io_Read_write &)
Definition: io.h:132
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
#define CGAL_kernel_precondition(EX)
Self & operator*=(const Self &v)
Self & operator/=(const Self &v)
FT operator*(const Self &v) const