template<class T> Point2<T> Line2D<T>::intersectPoint(const Line2D<T> &l2) const { T d = (a.X - b.X)*(l2.getA().Y - l2.getB().Y) - (a.Y - b.Y)*(l2.getA().X - l2.getB().X); T intersectX = ((l2.getA().X - l2.getB().X) * (a.X*b.Y - a.Y*b.X) - (a.X - b.X) * (l2.getA().X*l2.getB().Y - l2.getA().Y*l2.getB().X)) / d; T intersectY = ((l2.getA().Y - l2.getB().Y) * (a.X*b.Y - a.Y*b.X) - (a.Y - b.Y) * (l2.getA().X*l2.getB().Y - l2.getA().Y*l2.getB().X)) / d; return Point2<T>(intersectX, intersectY); }
toxi::geom::Vec2D toxi::geom::Polygon2D::getRandomPoint() { std::vector< Line2D > edges = getEdges(); int numEdges = edges.size(); Line2D ea = edges.at( static_cast< int > ( toxi::math::MathUtils::random( numEdges ) ) ); Line2D * eb = nullptr; // and another one, making sure it's different while (eb == nullptr || *eb == ea) { eb = &edges.at( static_cast< int > ( toxi::math::MathUtils::random( numEdges ) ) ); } // pick a random point on edge A Vec2D p = ea.getA().interpolateTo(ea.getB(), toxi::math::MathUtils::random( 1.0 ) ); // then randomly interpolate to another random point on edge B Vec2D ret = p.interpolateToSelf( eb->getA().interpolateTo(eb->getB(), toxi::math::MathUtils::random( 1.0 ) ), static_cast< float > ( toxi::math::MathUtils::random( 1.0 ) ) ); delete eb; return ret; }
/*! */ bool Bhv_GoalieChaseBall::is_ball_shoot_moving( const PlayerAgent * agent ) { const ServerParam & SP = ServerParam::i(); const WorldModel & wm = agent->world(); if ( wm.ball().distFromSelf() > 30.0 ) { return false; } #if 1 if ( wm.ball().pos().x > -34.5 ) { return false; } #endif // check opponent kicker if ( wm.existKickableOpponent() ) { dlog.addText( Logger::TEAM, __FILE__": check shoot moving. opponent kickable " ); return false; } else if ( wm.existKickableTeammate() ) { dlog.addText( Logger::TEAM, __FILE__": check shoot moving. teammate kickable" ); return false; } if ( wm.ball().vel().absX() < 0.1 ) { if ( wm.ball().pos().x < -46.0 && wm.ball().pos().absY() < SP.goalHalfWidth() + 2.0 ) { dlog.addText( Logger::TEAM, __FILE__": check shoot moving. bvel.x(%f) is ZERO. but near to goal", wm.ball().vel().x ); return true; } dlog.addText( Logger::TEAM, __FILE__": check shoot moving. bvel,x is small" ); return false; } const Line2D ball_line( wm.ball().pos(), wm.ball().vel().th() ); const double intersection_y = ball_line.getY( -SP.pitchHalfLength() ); if ( std::fabs( ball_line.getB() ) > 0.1 && std::fabs( intersection_y ) < SP.goalHalfWidth() + 2.0 ) { if ( wm.ball().pos().x < -40.0 && wm.ball().pos().absY() < 15.0 ) { const Vector2D end_point = wm.ball().pos() + wm.ball().vel() / ( 1.0 - SP.ballDecay()); if ( wm.ball().vel().r() > 0.5 // 1.0 && end_point.x < -SP.pitchHalfLength() + 2.0 ) { dlog.addText( Logger::TEAM, __FILE__": shoot to Y(%.1f). ball_line a=%.1f, b=%.1f, c=%.1f", intersection_y, ball_line.getA(), ball_line.getB(), ball_line.getC() ); return true; } } } return false; }