Wie kann man besonders schnell(performancesparend) berechnen ob ein Punkt im einem Dreieck liegt.
Mein bisheriger Code funktioniert nur begrenzt. Sobalt man Punkte vertauscht gibt es Fehler. Zusätzlich ist er wahrscheinlich zu langsam für dass was ich vorhabe:
Spoiler anzeigen
Alles anzeigen
Weswegen ich soviel Wert auf Geschwindigkeit lege, hat den Grund, dass der Code bis zu 1000 mal pro Step ausgeführt werden könnte.
Hoffe ihr könnt mir weiterhelfen.
Mein bisheriger Code funktioniert nur begrenzt. Sobalt man Punkte vertauscht gibt es Fehler. Zusätzlich ist er wahrscheinlich zu langsam für dass was ich vorhabe:
GML-Quellcode
- var ax, ay, bx, by, cx, cy, px, py, pos_h1, pos_h2, pos_h3, w1, h1, w2, h2, w3, h3;
- ax = 64;
- ay = 128;
- bx = 128;
- by = 256;
- cx = 512;
- cy = 384;
- px = mouse_x;
- py = mouse_y;
- w1 = max(ax,bx) - min(ax,bx);
- h1 = max(ay,by) - min(ay,by);
- pos_h1 = (py - min(ay,by))/h1;
- w2 = max(cx,bx) - min(cx,bx);
- h2 = max(cy,by) - min(cy,by);
- pos_h2 = (py - min(cy,by))/h2;
- w3 = max(ax,cx) - min(ax,cx);
- h3 = max(ay,cy) - min(ay,cy);
- pos_h3 = (py - min(ay,cy))/h3;
- if(bx < ax)
- pos_h1 = 1-pos_h1;
- if(cx < bx)
- pos_h2 = 1-pos_h2;
- if(cx < ax)
- pos_h3 = 1-pos_h3;
- arg1 = px >= pos_h1*w1+min(ax,bx);
- arg2 = px >= pos_h2*w2+min(cx,bx);
- arg3 = px <= pos_h3*w3+min(ax,cx);
- if(arg1 and arg2 and arg3)
- draw_set_color(c_lime);
- else
- draw_set_color(c_black);
- draw_triangle(ax, ay, bx, by, cx, cy, false);
Weswegen ich soviel Wert auf Geschwindigkeit lege, hat den Grund, dass der Code bis zu 1000 mal pro Step ausgeführt werden könnte.
Hoffe ihr könnt mir weiterhelfen.