bool JarvisMarch:: isLess(const Vec& p1, const Vec& p2) throw() { double f=cross(p1,p2); return f>0 || (EQDOUBLE(f,0) && isFurther(p1,p2)); }
// ---------------------------------------------------------------------- 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(); } }
int JarvisMarch:: index_of_lowest_point() throw() { int i, min=0; for (i=1; i<size_of_polygon_; i++){ if (polygon_[i].y()<polygon_[min].y() || (EQDOUBLE(polygon_[i].y(),polygon_[min].y()) && polygon_[i].x()<polygon_[min].x())) { min=i; } } return min; }
bool Segment2D:: check_for_intersections(const Segment2D& p_seg, Vec& ipoint) const throw() { if (equals(p_seg)) { return true; } // compute point of intersection: //xA = x1 + lambda*(x2-x1) //yA = y1 + lambda*(y2-y1) double x1 = source_.x(); double x2 = sink_.x(); double y1 = source_.y(); double y2 = sink_.y(); //xB = x3 + mue*(x4-x3) //yB = y3 + mue*(y4-y3) double x3 = p_seg.get_source().x(); double x4 = p_seg.get_sink().x(); double y3 = p_seg.get_source().y(); double y4 = p_seg.get_sink().y(); double mue = (x1*y2 + x2*y3 + x3*y1 - x2*y1 - x3*y2 - x1*y3) / (x1*y4 + x4*y2 + x2*y3 + x3*y1 - x4*y1 - x1*y3 -x3*y2 - x2*y4); double lambda = (x3 + mue*x4 - mue*x3 -x1) / (x2 - x1); // s1: point of intersection located on this segment (owner) double x_s1 = x1 + lambda*(x2-x1); double y_s1 = y1 + lambda*(y2-y1); // s2: point of intersection located on p_seg double x_s2 = x3 + mue*(x4-x3); double y_s2 = y3 + mue*(y4-y3); //---------------------------------------------------------- // (s1==s2?) if(EQDOUBLE(x_s1, x_s2) && EQDOUBLE(y_s1, y_s2)) { //the point of intersection can not be an end point of a segment! if( !((EQDOUBLE(x_s1, source_.x()) && EQDOUBLE(y_s1, source_.y()) ) || (EQDOUBLE(x_s1, sink_.x()) && EQDOUBLE(y_s1, sink_.y())) )) { // does the point of intersection s lie on both segments? (segments are no lines!) Vec s; s = Vec(x_s1, y_s1, 0.0); if(point_on_segment(s) && p_seg.point_on_segment(s)) { ipoint=s; return true; } } } return false; // returns false if there does not exist any point of intersection between seg1 and seg2 }