1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
21 #define INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
23 #include <basegfx/tuple/b3dtuple.hxx>
24 #include <basegfx/basegfxdllapi.h>
30 /** Base Point class with three double values
32 This class derives all operators and common handling for
33 a 3D data class from B3DTuple. All necessary extensions
34 which are special for 3D Vectors are added here.
38 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3DVector
: public ::basegfx::B3DTuple
41 /** Create a 3D Vector
43 The vector is initialized to (0.0, 0.0, 0.0)
49 /** Create a 3D Vector
52 This parameter is used to initialize the X-coordinate
56 This parameter is used to initialize the Y-coordinate
60 This parameter is used to initialize the Z-coordinate
63 B3DVector(double fX
, double fY
, double fZ
)
64 : B3DTuple(fX
, fY
, fZ
)
67 /** constructor with tuple to allow copy-constructing
68 from B3DTuple-based classes
70 B3DVector(const ::basegfx::B3DTuple
& rTuple
)
74 /** *=operator to allow usage from B3DVector, too
76 B3DVector
& operator*=( const B3DVector
& rPnt
)
84 /** *=operator to allow usage from B3DVector, too
86 B3DVector
& operator*=(double t
)
94 /** assignment operator to allow assigning the results
95 of B3DTuple calculations
97 B3DVector
& operator=( const ::basegfx::B3DTuple
& rVec
)
105 /** Calculate the length of this 3D Vector
107 @return The Length of the 3D Vector
109 double getLength() const
111 double fLen(scalar(*this));
112 if((0.0 == fLen
) || (1.0 == fLen
))
117 /** Calculate the length in the XZ-Plane for this 3D Vector
119 @return The XZ-Plane Length of the 3D Vector
121 double getXZLength() const
123 double fLen((mfX
* mfX
) + (mfZ
* mfZ
)); // #i73040#
124 if((0.0 == fLen
) || (1.0 == fLen
))
129 /** Calculate the length in the YZ-Plane for this 3D Vector
131 @return The YZ-Plane Length of the 3D Vector
133 double getYZLength() const
135 double fLen((mfY
* mfY
) + (mfZ
* mfZ
));
136 if((0.0 == fLen
) || (1.0 == fLen
))
141 /** Set the length of this 3D Vector
144 The to be achieved length of the 3D Vector
146 B3DVector
& setLength(double fLen
)
148 double fLenNow(scalar(*this));
150 if(!::basegfx::fTools::equalZero(fLenNow
))
152 const double fOne(1.0);
154 if(!::basegfx::fTools::equal(fOne
, fLenNow
))
156 fLen
/= sqrt(fLenNow
);
167 /** Normalize this 3D Vector
169 The length of the 3D Vector is set to 1.0
171 B3DVector
& normalize();
173 /** get a 3D Vector which is perpendicular to this and a given 3D Vector
175 @attention This only works if this and the given 3D Vector are
178 @param rNormalizedVec
179 A normalized 3D Vector.
182 A 3D Vector perpendicular to this and the given one
184 B3DVector
getPerpendicular(const B3DVector
& rNormalizedVec
) const;
186 /** Calculate the Scalar product
188 This method calculates the Scalar product between this
189 and the given 3D Vector.
195 The Scalar Product of two 3D Vectors
197 double scalar(const B3DVector
& rVec
) const
199 return ((mfX
* rVec
.mfX
) + (mfY
* rVec
.mfY
) + (mfZ
* rVec
.mfZ
));
202 /** Transform vector by given transformation matrix.
204 Since this is a vector, translational components of the
205 matrix are disregarded.
207 B3DVector
& operator*=( const B3DHomMatrix
& rMat
);
209 static const B3DVector
& getEmptyVector()
211 return static_cast<const B3DVector
&>( ::basegfx::B3DTuple::getEmptyTuple() );
215 // external operators
218 /** Test two vectors which need not to be normalized for parallelism
227 bool if the two values are parallel. Also true if
228 one of the vectors is empty.
230 BASEGFX_DLLPUBLIC
bool areParallel( const B3DVector
& rVecA
, const B3DVector
& rVecB
);
232 /** Transform vector by given transformation matrix.
234 Since this is a vector, translational components of the
235 matrix are disregarded.
237 BASEGFX_DLLPUBLIC B3DVector
operator*( const B3DHomMatrix
& rMat
, const B3DVector
& rVec
);
239 /** Calculate the Cross Product of two 3D Vectors
248 The Cross Product of both 3D Vectors
250 inline B3DVector
cross(const B3DVector
& rVecA
, const B3DVector
& rVecB
)
253 rVecA
.getY() * rVecB
.getZ() - rVecA
.getZ() * rVecB
.getY(),
254 rVecA
.getZ() * rVecB
.getX() - rVecA
.getX() * rVecB
.getZ(),
255 rVecA
.getX() * rVecB
.getY() - rVecA
.getY() * rVecB
.getX());
258 } // end of namespace basegfx
260 #endif // INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */