シンプルな実装
変数
float box_x; // 矩形のX座標
float box_y; // 矩形のY座標
float box_width; // 矩形の幅
float box_height; // 矩形の高さ
float box_angle; // 矩形の回転角度(180° = π)
float point_x; // 点のX座標
float point_y; // 点のY座標
判定計算
float s = -sinf(box_angle);
float c = cosf(box_angle);
float dx = point_x - box_x;
float dy = point_y - box_y;
float xx = dx * c - dy * s;
float yy = dx * s + dy * c;
bool result = (0 <= xx && xx < box_width && 0 <= yy && yy < box_height);
アンカーやサイズを含む実装
変数
float box_x; // 矩形のX座標
float box_y; // 矩形のY座標
float box_width; // 矩形の幅
float box_height; // 矩形の高さ
float box_angle; // 矩形の回転角度(180° = π)
float box_anchor_x; // 矩形のアンカー(回転の基点)X座標
float box_anchor_y; // 矩形のアンカー(回転の基点)Y座標
float box_size; // 矩形のサイズ(100% = 1.0)
float point_x; // 点のX座標
float point_y; // 点のY座標
判定計算
float s = -sinf(box_angle);
float c = cosf(box_angle);
float dx = point_x - box_x;
float dy = point_y - box_y;
float xx = dx * c - dy * s + box_anchor_x * box_size;
float yy = dx * s + dy * c + box_anchor_y * box_size;
bool result = (0 <= xx && xx < (box_width * box_size) && 0 <= yy && yy < (box_height * box_size));