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; }