Library of Assembled Shared Sources
parallelogram_3d.inl
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_PARALLELOGRAM_3D_INL
46#define LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_PARALLELOGRAM_3D_INL
47
48#include "prim_common.h"
49#include "parallelogram_3d.h"
51
52namespace lass
53{
54namespace prim
55{
56
57/** constructs an empty parallelogram.
58 * support is origin and sizes are zero.
59 */
60template <typename T>
64
65
66
67/** Constructs a parallelogram with a support and two sizes
68 */
69template <typename T>
70Parallelogram3D<T>::Parallelogram3D(const TPoint& support, const TVector& sizeU, const TVector& sizeV):
71 support_(support),
72 sizeU_(sizeU),
73 sizeV_(sizeV)
74{
75}
76
77
78
79template <typename T> inline
80const typename Parallelogram3D<T>::TPoint&
81Parallelogram3D<T>::support() const
82{
83 return support_;
84}
85
86
87
88template <typename T> inline
89typename Parallelogram3D<T>::TPoint&
90Parallelogram3D<T>::support()
91{
92 return support_;
93}
94
95
96
97template <typename T> inline
98const typename Parallelogram3D<T>::TVector&
99Parallelogram3D<T>::sizeU() const
100{
101 return sizeU_;
105
106template <typename T> inline
107typename Parallelogram3D<T>::TVector&
108Parallelogram3D<T>::sizeU()
109{
110 return sizeU_;
113
114
115template <typename T> inline
116const typename Parallelogram3D<T>::TVector&
117Parallelogram3D<T>::sizeV() const
118{
119 return sizeV_;
120}
121
122
123
124template <typename T> inline
125typename Parallelogram3D<T>::TVector&
126Parallelogram3D<T>::sizeV()
127{
128 return sizeV_;
129}
130
131
132
133template <typename T>
134const typename Parallelogram3D<T>::TPlane
135Parallelogram3D<T>::plane() const
136{
137 return TPlane(cross(sizeU_, sizeV_), support_);
138}
139
140
141
142/** returns squared area of parallelogram to avoid the square root.
143 * @return num::sqr(area()) but faster :)
144 */
145template <typename T>
146const typename Parallelogram3D<T>::TValue
148{
149 return cross(sizeU_, sizeV_).squaredNorm();
150}
151
152
153
154/** @copydoc SimplePolygon3D::area
155 */
156template <typename T>
157const typename Parallelogram3D<T>::TValue
159{
160 return num::sqrt(squaredArea());
161}
162
163
164
165/** @copydoc SimplePolygon3D::perimeter
166 */
167template <typename T>
168const typename Parallelogram3D<T>::TValue
170{
171 return 2 * (sizeU_.norm() + sizeV_.norm());
172}
173
174
175
176template <typename T>
177const typename Parallelogram3D<T>::TPoint
178Parallelogram3D<T>::point(TParam u, TParam v) const
179{
180 return support_ + u * sizeU_ + v * sizeV_;
181}
182
183
184
185template <typename T> inline
186const typename Parallelogram3D<T>::TPoint
187Parallelogram3D<T>::point(const TUV& uv) const
188{
189 return point(uv.x, uv.y);
190}
191
192
193
194template <typename T>
195const typename Parallelogram3D<T>::TUV
196Parallelogram3D<T>::uv(const TPoint& point) const
197{
198 TVector reciprocalU;
199 TVector reciprocalV;
200 impl::Plane3DImplDetail::generateReciprocal(sizeU_, sizeV_, reciprocalU, reciprocalV);
201 const TVector relative = point - support_;
202 return TUV(dot(relative, reciprocalU), dot(relative, reciprocalV));
203}
204
205
206
207/** @copydoc SimplePolygon3D::isSimple
208 * @par Parallelogram specific:
209 * A parallelogram is always simple
210 */
211template <typename T>
213{
214 return true;
215}
216
217
218
219/** @copydoc SimplePolygon3D::isConvex
220 * @par Parallelogram specific:
221 * A parallelogram is always convex
222 */
223template <typename T>
225{
226 return true;
227}
228
229
230
231/** @copydoc SimplePolygon3D::isReflex
232 * @par Parallelogram specific:
233 * A parallelogram never has reflex vertices
234 */
235template <typename T>
237{
238 return false;
239}
240
241
242
243// --- private -------------------------------------------------------------------------------------
244
245
246
247// --- free ----------------------------------------------------------------------------------------
248
249/** @relates lass::prim::Parallelogram3D
250 */
251template <typename T>
252io::XmlOStream& operator<<(io::XmlOStream& stream, const Parallelogram3D<T>& parallelogram)
253{
254 LASS_ENFORCE_STREAM(stream) << "<Parallelogram3D>\n";
255 stream << "<support>" << parallelogram.support() << "</support>\n";
256 stream << "<sizeU>" << parallelogram.sizeU() << "</sizeU>\n";
257 stream << "<sizeV>" << parallelogram.sizeV() << "</sizeV>\n";
258 stream << "</Parallelogram3D>\n";
259 return stream;
260}
261
262
263
264/** @relates lass::prim::Parallelogram3D
265 */
266template <typename T>
267std::ostream& operator<<(std::ostream& stream, const Parallelogram3D<T>& parallelogram)
268{
269 LASS_ENFORCE_STREAM(stream)
270 << "{S=" << parallelogram.support() << ", U=" << parallelogram.sizeU()
271 << ", V=" << parallelogram.sizeV() << "}";
272 return stream;
273}
274
275
276
277}
278
279}
280
281#endif
282
283// EOF
Output stream for writing a selection of geometric primitives to XML files.
A very simple 3D polygon :)
const TValue area() const
return area of the polygons surface.
Parallelogram3D()
constructs an empty parallelogram.
bool isReflex(int indexOfVertex) const
return true if inner angle of vertex is reflex (is > 180 degrees).
bool isConvex() const
return true if polygon is convex, false if not.
bool isSimple() const
return true if polygon is simple, false if not.
const TValue perimeter() const
return sum of the lengths of all edges
const TValue squaredArea() const
returns squared area of parallelogram to avoid the square root.
set of geometrical primitives
Definition aabb_2d.h:81
Library for Assembled Shared Sources.
Definition config.h:53
static void generateReciprocal(const Vector3D< T > &iDirU, const Vector3D< T > &iDirV, Vector3D< T > &oReciprocalDirU, Vector3D< T > &oReciprocalDirV)
generate reciprocal direction vectors Ur and Vr given directions U and V.