C++ (Qt)bool PointInsideNGon( const QPointF & src, // point to test const QRectF & R, // N-gon bounding rectangle int N, // N-gpn side count qreal phase = 0 ) // 0 = corner on x-axis{// point in local space QPointF pt = src - R.center(); pt.rx() /= R.width() / 2; pt.ry() /= R.height() / 2; // angle inside sector qreal angle = atan2(-pt.y(), pt.x()) + phase; qreal step = M_PI * 2 / N; int num = (int) (angle / step); angle = (step + 0.5) * num; // check dot return pt.x() * cos(angle) + pt.y() * sin(angle) <= cos(step / 2);}