// ----------------------------------------------------------------------
 void
 XYZFileElevationTask::
 z_place_scale( shawn::SimulationController& sc,
               const XYZFile& f,
               shawn::Vec& bp, shawn::Vec& s )
    throw( std::runtime_error )
 {
    bp = Vec( bp.x(), bp.y(),
              sc.environment().optional_double_param("z_base",0.0) );
    s = Vec( s.x(), s.y(),
             sc.environment().optional_double_param("z_scale",1.0) );
 }
예제 #2
0
   // ----------------------------------------------------------------------
   void
   rotate_2D( double angle, shawn::Vec& coord, const shawn::Vec& origin )
      throw()
   {
      double cos_angle = cos( angle );
      double sin_angle = sin( angle );

      coord = shawn::Vec(
         ((coord.x() - origin.x()) * cos_angle) - ((coord.y() - origin.y()) * sin_angle) + origin.x(),
         ((coord.y() - origin.y()) * cos_angle) + ((coord.x() - origin.x()) * sin_angle) + origin.y(),
         coord.z() );
   }
예제 #3
0
 XYZFileElevation::
 XYZFileElevation( XYZFile* f,
                   const shawn::Vec& base_point,
                   double xscale, double yscale, double zscale,
                   const std::string& name )
    : box_        ( Vec( base_point.x(), 
                         base_point.y(),
                         -std::numeric_limits<double>::max()),
                    Vec( base_point.x() + xscale*double(f->x_dimension()),
                         base_point.y() + yscale*double(f->y_dimension()),
                         std::numeric_limits<double>::max()) ),
      name_       ( name ),
      base_point_ ( base_point ),
      x_scale_    ( xscale ),
      y_scale_    ( yscale ),
      z_scale_    ( zscale ),
      xyz_data_   ( f )
 {}
예제 #4
0
   // ----------------------------------------------------------------------
   double
   angle_vec( const shawn::Vec& vec )
      throw()
   {
      if ( vec.x() == 0 && vec.y() >= 0 )
         return 0.5 * M_PI;
      else if ( vec.x() == 0 && vec.y() < 0 )
         return 1.5 * M_PI;

      if ( vec.y() == 0 && vec.x() >= 0 )
         return 0;
      else if ( vec.y() == 0 && vec.x() < 0 )
         return M_PI;

      if ( vec.y() >= 0 )
         return acos( vec.x() / vec.euclidean_norm() );
      else
         return 2.0*M_PI - acos( vec.x() / vec.euclidean_norm() );
   }
예제 #5
0
   // ----------------------------------------------------------------------
   bool
   Uniform25DPointGenerator::
   make_feasible( shawn::Vec& v )
      throw()
   {
      assert( lower_ != NULL ); assert( upper_ != NULL );
      double l = lower_->value(v);
      double u = upper_->value(v);
      if( u<l ) return false;

      v = Vec(v.x(),v.y(),  l + uniform_random_0i_1i()*(u-l) );
      return true;
   }
예제 #6
0
   // ----------------------------------------------------------------------
   double 
   XYZFileElevation::
   value( const shawn::Vec& p )
      const throw()
   {
      double xlocal = (p.x()-base_point_.x())/x_scale_;
      double ylocal = (p.y()-base_point_.y())/y_scale_;

      int xcell = int(floor(xlocal));
      int ycell = int(floor(ylocal));

      double xfrac = xlocal-double(xcell);
      double yfrac = ylocal-double(ycell);

      if( EQDOUBLE(xfrac,0.0) && (xcell == xyz_data_->x_dimension()-1) )
         { --xcell; xfrac=1.0; }
      if( EQDOUBLE(yfrac,0.0) && (ycell == xyz_data_->y_dimension()-1) )
         { --ycell; yfrac=1.0; }

      if( (xcell<0) || (ycell<0) ||
          (xcell>=xyz_data_->x_dimension()-1) ||
          (ycell>=xyz_data_->y_dimension()-1) )
         return 0.0;

      if( xfrac > yfrac )
         {
            // lower triangle
            double a = xyz_data_->value(xcell,ycell);
            double b = xyz_data_->value(xcell+1,ycell);
            double c = xyz_data_->value(xcell+1,ycell+1);
            return  (a + xfrac*(b-a) + yfrac*(c-b))*z_scale_ + base_point_.z();
         }
      else
         {
            // upper triangle
            double a = xyz_data_->value(xcell,ycell);
            double b = xyz_data_->value(xcell,ycell+1);
            double c = xyz_data_->value(xcell+1,ycell+1);
            return  (a + yfrac*(b-a) + xfrac*(c-b))*z_scale_ + base_point_.z();
         }
   }