height_map_examples.cc
Go to the documentation of this file.
00001 /******************************************************************************
00002 Copyright (c) 2018, Alexander W. Winkler. All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 
00010 * Redistributions in binary form must reproduce the above copyright notice,
00011   this list of conditions and the following disclaimer in the documentation
00012   and/or other materials provided with the distribution.
00013 
00014 * Neither the name of the copyright holder nor the names of its
00015   contributors may be used to endorse or promote products derived from
00016   this software without specific prior written permission.
00017 
00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00022 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00024 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00025 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 ******************************************************************************/
00029 
00030 #include <towr/terrain/examples/height_map_examples.h>
00031 
00032 namespace towr {
00033 
00034 
00035 FlatGround::FlatGround(double height)
00036 {
00037   height_ = height;
00038 }
00039 
00040 double
00041 Block::GetHeight (double x, double y) const
00042 {
00043   double h = 0.0;
00044 
00045   // very steep ramp leading up to block
00046   if (block_start <= x && x <=block_start+eps_)
00047     h = slope_*(x-block_start);
00048 
00049   if (block_start+eps_ <= x && x <= block_start+length_)
00050     h = height_;
00051 
00052   return h;
00053 }
00054 
00055 double
00056 Block::GetHeightDerivWrtX (double x, double y) const
00057 {
00058   double dhdx = 0.0;
00059 
00060   // very steep ramp leading up to block
00061   if (block_start <= x && x <=block_start+eps_)
00062     dhdx = slope_;
00063 
00064   return dhdx;
00065 }
00066 
00067 
00068 // STAIRS
00069 double
00070 Stairs::GetHeight (double x, double y) const
00071 {
00072   double h = 0.0;
00073 
00074   if (x>=first_step_start_)
00075     h = height_first_step;
00076 
00077   if (x>=first_step_start_+first_step_width_)
00078     h = height_second_step;
00079 
00080   if (x>=first_step_start_+first_step_width_+width_top)
00081     h = 0.0;
00082 
00083   return h;
00084 }
00085 
00086 
00087 // GAP
00088 double
00089 Gap::GetHeight (double x, double y) const
00090 {
00091   double h = 0.0;
00092 
00093   // modelled as parabola
00094   if (gap_start_ <= x && x <= gap_end_x)
00095     h = a*x*x + b*x + c;
00096 
00097   return h;
00098 }
00099 
00100 double
00101 Gap::GetHeightDerivWrtX (double x, double y) const
00102 {
00103   double dhdx = 0.0;
00104 
00105   if (gap_start_ <= x && x <= gap_end_x)
00106     dhdx = 2*a*x + b;
00107 
00108   return dhdx;
00109 }
00110 
00111 double
00112 Gap::GetHeightDerivWrtXX (double x, double y) const
00113 {
00114   double dzdxx = 0.0;
00115 
00116   if (gap_start_ <= x && x <= gap_end_x)
00117     dzdxx = 2*a;
00118 
00119   return dzdxx;
00120 }
00121 
00122 
00123 // SLOPE
00124 double
00125 Slope::GetHeight (double x, double y) const
00126 {
00127   double z = 0.0;
00128   if (x >= slope_start_)
00129     z = slope_*(x-slope_start_);
00130 
00131   // going back down
00132   if (x >= x_down_start_) {
00133     z = height_center - slope_*(x-x_down_start_);
00134   }
00135 
00136   // back on flat ground
00137   if (x >= x_flat_start_)
00138     z = 0.0;
00139 
00140   return z;
00141 }
00142 
00143 double
00144 Slope::GetHeightDerivWrtX (double x, double y) const
00145 {
00146   double dzdx = 0.0;
00147   if (x >= slope_start_)
00148     dzdx = slope_;
00149 
00150   if (x >= x_down_start_)
00151     dzdx = -slope_;
00152 
00153   if (x >= x_flat_start_)
00154     dzdx = 0.0;
00155 
00156   return dzdx;
00157 }
00158 
00159 
00160 // Chimney
00161 double
00162 Chimney::GetHeight (double x, double y) const
00163 {
00164   double z = 0.0;
00165 
00166   if (x_start_<=x && x<=x_end_)
00167     z = slope_*(y-y_start_);
00168 
00169   return z;
00170 }
00171 
00172 double
00173 Chimney::GetHeightDerivWrtY (double x, double y) const
00174 {
00175   double dzdy = 0.0;
00176 
00177   if (x_start_<= x && x<= x_end_)
00178     dzdy = slope_;
00179 
00180   return dzdy;
00181 }
00182 
00183 
00184 // Chimney LR
00185 double
00186 ChimneyLR::GetHeight (double x, double y) const
00187 {
00188   double z = 0.0;
00189 
00190   if (x_start_<=x && x<=x_end1_)
00191     z = slope_*(y-y_start_);
00192 
00193   if (x_end1_<=x && x<=x_end2_)
00194     z = -slope_*(y+y_start_);
00195 
00196   return z;
00197 }
00198 
00199 double
00200 ChimneyLR::GetHeightDerivWrtY (double x, double y) const
00201 {
00202   double dzdy = 0.0;
00203 
00204   if (x_start_ <= x && x <= x_end1_)
00205     dzdy = slope_;
00206 
00207   if (x_end1_<=x && x<=x_end2_)
00208     dzdy = -slope_;
00209 
00210   return dzdy;
00211 }
00212 
00213 } /* namespace towr */


towr
Author(s): Alexander W. Winkler
autogenerated on Mon Apr 15 2019 02:42:32