Pixel-Composer/scripts/point_rect_overlap/point_rect_overlap.gml
2022-01-13 11:24:03 +07:00

24 lines
593 B
Plaintext

function point_rectangle_overlap(w, h, angle) {
var x0, y0;
var a1 = radtodeg(arctan2(h, w));
var a2 = 90 - a1;
if(angle < a1) {
x0 = w;
y0 = h / 2 - w / 2 * tan(degtorad(angle));
} else if(angle < a1 + a2 * 2) {
x0 = w / 2 - h / 2 * tan(degtorad(angle - 90));
y0 = 0;
} else if(angle < a1 + a2 * 2 + a1 * 2) {
x0 = 0;
y0 = h / 2 + w / 2 * tan(degtorad(angle - 180));
} else if(angle < a1 + a2 * 2 + a1 * 2 + a2 * 2) {
x0 = w / 2 + h / 2 * tan(degtorad(angle - 270));
y0 = h;
} else {
x0 = w;
y0 = h / 2 - w / 2 * tan(degtorad(angle));
}
return [x0, y0];
}