mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-14 06:23:55 +01:00
24 lines
593 B
Plaintext
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];
|
|
} |