height_map.h
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2018, Alexander W. Winkler. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6 
7 * Redistributions of source code must retain the above copyright notice, this
8  list of conditions and the following disclaimer.
9 
10 * Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 * Neither the name of the copyright holder nor the names of its
15  contributors may be used to endorse or promote products derived from
16  this software without specific prior written permission.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ******************************************************************************/
29 
30 #ifndef TOWR_HEIGHT_MAP_H_
31 #define TOWR_HEIGHT_MAP_H_
32 
33 #include <memory>
34 #include <vector>
35 #include <Eigen/Dense>
36 
38 
39 namespace towr {
40 
53 class HeightMap {
54 public:
55  using Ptr = std::shared_ptr<HeightMap>;
56  using Vector3d = Eigen::Vector3d;
57 
59 
60  HeightMap() = default;
61  virtual ~HeightMap () = default;
62 
68  virtual double GetHeight(double x, double y) const = 0;
69 
77  double GetDerivativeOfHeightWrt(Dim2D dim, double x, double y) const;
78 
86  Vector3d GetNormalizedBasis(Direction direction, double x, double y) const;
87 
97  double x, double y) const;
101  double GetFrictionCoeff() const { return friction_coeff_; };
102 
103 protected:
104  double friction_coeff_ = 0.5;
105 
106 private:
107  using DimDerivs = std::vector<Dim2D>;
108 
117  Vector3d GetBasis(Direction direction, double x, double y,
118  const DimDerivs& dim_deriv= {}) const;
119 
120  Vector3d GetNormal(double x, double y, const DimDerivs& = {}) const;
121  Vector3d GetTangent1(double x, double y, const DimDerivs& = {}) const;
122  Vector3d GetTangent2(double x, double y, const DimDerivs& = {}) const;
123 
124  double GetSecondDerivativeOfHeightWrt(Dim2D dim1, Dim2D dim2,
125  double x, double y) const;
126 
128  const Vector3d& non_normalized, int index) const;
129 
130  // first derivatives that must be implemented by the user
131  virtual double GetHeightDerivWrtX(double x, double y) const { return 0.0; };
132  virtual double GetHeightDerivWrtY(double x, double y) const { return 0.0; };
133 
134  // second derivatives with respect to first letter, then second
135  virtual double GetHeightDerivWrtXX(double x, double y) const { return 0.0; };
136  virtual double GetHeightDerivWrtXY(double x, double y) const { return 0.0; };
137  virtual double GetHeightDerivWrtYX(double x, double y) const { return 0.0; };
138  virtual double GetHeightDerivWrtYY(double x, double y) const { return 0.0; };
139 };
140 
141 } /* namespace towr */
142 
143 #endif /* TOWR_HEIGHT_MAP_H_ */
Vector3d GetBasis(Direction direction, double x, double y, const DimDerivs &dim_deriv={}) const
returns either the terrain normal/tangent or its derivative.
Definition: height_map.cc:53
virtual double GetHeightDerivWrtY(double x, double y) const
Definition: height_map.h:132
virtual double GetHeightDerivWrtYY(double x, double y) const
Definition: height_map.h:138
Holds the height and slope of the terrain.
Definition: height_map.h:53
Vector3d GetDerivativeOfNormalizedVectorWrtNonNormalizedIndex(const Vector3d &non_normalized, int index) const
Definition: height_map.cc:126
Vector3d GetTangent1(double x, double y, const DimDerivs &={}) const
Definition: height_map.cc:97
virtual double GetHeightDerivWrtYX(double x, double y) const
Definition: height_map.h:137
Vector3d GetNormalizedBasis(Direction direction, double x, double y) const
Returns either the vector normal or tangent to the terrain patch.
Definition: height_map.cc:47
double GetFrictionCoeff() const
Definition: height_map.h:101
double friction_coeff_
Definition: height_map.h:104
double GetSecondDerivativeOfHeightWrt(Dim2D dim1, Dim2D dim2, double x, double y) const
Definition: height_map.cc:135
virtual ~HeightMap()=default
Eigen::Vector3d Vector3d
Definition: height_map.h:56
Vector3d GetDerivativeOfNormalizedBasisWrt(Direction direction, Dim2D dim, double x, double y) const
How the terrain normal/tangent vectors change when moving in x or y.
Definition: height_map.cc:65
virtual double GetHeightDerivWrtX(double x, double y) const
Definition: height_map.h:131
virtual double GetHeightDerivWrtXX(double x, double y) const
Definition: height_map.h:135
virtual double GetHeight(double x, double y) const =0
virtual double GetHeightDerivWrtXY(double x, double y) const
Definition: height_map.h:136
std::vector< Dim2D > DimDerivs
dimensional derivatives
Definition: height_map.h:107
double GetDerivativeOfHeightWrt(Dim2D dim, double x, double y) const
How the height value changes at a 2D position in direction dim.
Definition: height_map.cc:37
Vector3d GetTangent2(double x, double y, const DimDerivs &={}) const
Definition: height_map.cc:112
HeightMap()=default
std::shared_ptr< HeightMap > Ptr
Definition: height_map.h:55
Vector3d GetNormal(double x, double y, const DimDerivs &={}) const
Definition: height_map.cc:78


towr_core
Author(s): Alexander W. Winkler
autogenerated on Sat Apr 7 2018 02:15:57