Hi i am running into problems. I can solve the triangle and the square, but i run into problems with the other shapes.
since i was able to solve the triangle I thought I will split the polygon into many triangles and then check on them, but i always fail. then i decided to also check on the lines of the triangles since i was not sure if they are included in the insideTriangle.
....
bool runPolygonAsTriangle(List polygon, List shot){
bool hit = false;
for (var i = 0, len = polygon.length; i+2 < len; ++i) {
List point1 = polygon[0];
List point2 = polygon[i+1];
List point3 = polygon[i+2];
List polygonTriangle = [point1,point2,point3];
bool inside = isInside(polygonTriangle, polygonTriangle.length, shot);
bool onLine = isOnLineOfTriangle(point1,point2,point3,shot);
stderr.writeln('shot $shot hit $inside inside triangle on lines $onLine of $polygonTriangle');
if(inside || onLine){
hit = true;
break;
}
}
return hit;
}
bool isOnLineOfTriangle(List p1,List p2,List p3, List shot){
bool value = false;
if(isOnLine(p1,p2,shot) || isOnLine(p1,p3,shot) || isOnLine(p2,p3,shot)){
value = true;
}
return value;
}
bool isOnLine(List p1,List p2,List shot){
return getDistance(p1, shot) + getDistance(p2, shot) == getDistance(p1, p2);
}
num getDistance(List p1, List p2) {
return sqrt(pow((p2[0] - p1[0]), 2) + pow((p2[1] - p1[1]), 2));
}
....
love any help