本文整理汇总了C++中Rect2D::intersection方法的典型用法代码示例。如果您正苦于以下问题:C++ Rect2D::intersection方法的具体用法?C++ Rect2D::intersection怎么用?C++ Rect2D::intersection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rect2D
的用法示例。
在下文中一共展示了Rect2D::intersection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ball_ray
/*!
*/
int
TackleGenerator::predictOpponentsReachStep( const WorldModel & wm,
const Vector2D & first_ball_pos,
const Vector2D & first_ball_vel,
const AngleDeg & ball_move_angle )
{
int first_min_step = 50;
#if 1
const ServerParam & SP = ServerParam::i();
const Vector2D ball_end_point = inertia_final_point( first_ball_pos,
first_ball_vel,
SP.ballDecay() );
if ( ball_end_point.absX() > SP.pitchHalfLength()
|| ball_end_point.absY() > SP.pitchHalfWidth() )
{
Rect2D pitch = Rect2D::from_center( 0.0, 0.0, SP.pitchLength(), SP.pitchWidth() );
Ray2D ball_ray( first_ball_pos, ball_move_angle );
Vector2D sol1, sol2;
int n_sol = pitch.intersection( ball_ray, &sol1, &sol2 );
if ( n_sol == 1 )
{
first_min_step = SP.ballMoveStep( first_ball_vel.r(), first_ball_pos.dist( sol1 ) );
#ifdef DEBUG_PRINT
dlog.addText( Logger::CLEAR,
"(predictOpponent) ball will be out. step=%d reach_point=(%.2f %.2f)",
first_min_step,
sol1.x, sol1.y );
#endif
}
}
#endif
int min_step = first_min_step;
for ( AbstractPlayerCont::const_iterator
o = wm.theirPlayers().begin(),
end = wm.theirPlayers().end();
o != end;
++o )
{
int step = predictOpponentReachStep( *o,
first_ball_pos,
first_ball_vel,
ball_move_angle,
min_step );
if ( step < min_step )
{
min_step = step;
}
}
return ( min_step == first_min_step
? 1000
: min_step );
}
示例2: final_segment
/*!
*/
double
TackleGenerator::evaluate( const WorldModel & wm,
const TackleResult & result )
{
const ServerParam & SP = ServerParam::i();
const Vector2D ball_end_point = inertia_final_point( wm.ball().pos(),
result.ball_vel_,
SP.ballDecay() );
const Segment2D ball_line( wm.ball().pos(), ball_end_point );
const double ball_speed = result.ball_speed_;
const AngleDeg ball_move_angle = result.ball_move_angle_;
#ifdef DEBUG_PRINT
dlog.addText( Logger::CLEAR,
"(evaluate) angle=%.1f speed=%.2f move_angle=%.1f end_point=(%.2f %.2f)",
result.tackle_angle_.degree(),
ball_speed,
ball_move_angle.degree(),
ball_end_point.x, ball_end_point.y );
#endif
//
// moving to their goal
//
if ( ball_end_point.x > SP.pitchHalfLength()
&& wm.ball().pos().dist2( SP.theirTeamGoalPos() ) < std::pow( 20.0, 2 ) )
{
const Line2D goal_line( Vector2D( SP.pitchHalfLength(), 10.0 ),
Vector2D( SP.pitchHalfLength(), -10.0 ) );
const Vector2D intersect = ball_line.intersection( goal_line );
if ( intersect.isValid()
&& intersect.absY() < SP.goalHalfWidth() )
{
double shoot_score = 1000000.0;
double speed_rate = 1.0 - std::exp( - std::pow( ball_speed, 2 )
/ ( 2.0 * std::pow( SP.ballSpeedMax()*0.5, 2 ) ) );
double y_rate = std::exp( - std::pow( intersect.absY(), 2 )
/ ( 2.0 * std::pow( SP.goalWidth(), 2 ) ) );
shoot_score *= speed_rate;
shoot_score *= y_rate;
#ifdef DEBUG_PRINT
dlog.addText( Logger::CLEAR,
"__ shoot %f (speed_rate=%f y_rate=%f)",
shoot_score, speed_rate, y_rate );
#endif
return shoot_score;
}
}
//
// moving to our goal
//
if ( ball_end_point.x < -SP.pitchHalfLength() )
{
const Line2D goal_line( Vector2D( -SP.pitchHalfLength(), 10.0 ),
Vector2D( -SP.pitchHalfLength(), -10.0 ) );
const Vector2D intersect = ball_line.intersection( goal_line );
if ( intersect.isValid()
&& intersect.absY() < SP.goalHalfWidth() + 1.0 )
{
double shoot_score = 0.0;
double y_penalty = ( -10000.0
* std::exp( - std::pow( intersect.absY() - SP.goalHalfWidth(), 2 )
/ ( 2.0 * std::pow( SP.goalHalfWidth(), 2 ) ) ) );
double speed_bonus = ( +10000.0
* std::exp( - std::pow( ball_speed, 2 )
/ ( 2.0 * std::pow( SP.ballSpeedMax()*0.5, 2 ) ) ) );
shoot_score = y_penalty + speed_bonus;
#ifdef DEBUG_PRINT
dlog.addText( Logger::CLEAR,
"__ in our goal %f (y_pealty=%f speed_bonus=%f)",
shoot_score, y_penalty, speed_bonus );
#endif
return shoot_score;
}
}
//
// normal evaluation
//
int opponent_reach_step = predictOpponentsReachStep( wm,
wm.ball().pos(),
result.ball_vel_,
ball_move_angle );
Vector2D final_point = inertia_n_step_point( wm.ball().pos(),
result.ball_vel_,
opponent_reach_step,
SP.ballDecay() );
{
Segment2D final_segment( wm.ball().pos(), final_point );
Rect2D pitch = Rect2D::from_center( 0.0, 0.0, SP.pitchLength(), SP.pitchWidth() );
Vector2D intersection;
int n = pitch.intersection( final_segment, &intersection, NULL );
if ( n > 0 )
{
//.........这里部分代码省略.........