1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| float AInfrastructureGraphManager::ScalarProjection(FVector v1, FVector v2) { //DotProduct()
float Ang = AngleBetweenVectors(v1, v2);
return v1.Size() * FMath::Cos(Ang);
}
bool AInfrastructureGraphManager::PolygonesAreColliding(TArray<FVector> Polygone1, TArray<FVector> Polygone2) { //Teste collision entre 2 polygones convexes quelconques
TArray<FVector> l_EveryAxis;
TArray<float> l_Poly1Projs, l_Poly2Projs; //Stocke les projections respectives des 2 polygones sur chaque axe
float l_minPoly1Proj, l_maxPoly1Proj, l_minPoly2Proj, l_maxPoly2Proj;
FVector l_Axis;
for (int32 i = 0; i < Polygone1.Num(); i++){
l_Axis = Polygone1[(i + 1) % Polygone1.Num()] - Polygone1[i];
l_Axis = FVector(-l_Axis.Y, l_Axis.X, 0.f);
l_Axis.Normalize();
l_EveryAxis.Add(l_Axis);
}
for (int32 i = 0; i < Polygone2.Num(); i++) {
l_Axis = Polygone2[(i + 1) % Polygone2.Num()] - Polygone2[i];
l_Axis = FVector(-l_Axis.Y, l_Axis.X, 0.f);
l_Axis.Normalize();
l_EveryAxis.Add(l_Axis);
}
for (int32 i = 0; i < l_EveryAxis.Num(); i++) {
for (int32 j = 0; j < Polygone1.Num(); j++) {
l_Poly1Projs.Add(ScalarProjection(Polygone1[j], l_EveryAxis[i]));
}
for (int32 j = 0; j < Polygone2.Num(); j++) {
l_Poly2Projs.Add(ScalarProjection(Polygone2[j], l_EveryAxis[i]));
}
l_minPoly1Proj = FMath::Min<float>(l_Poly1Projs);
l_maxPoly1Proj = FMath::Max<float>(l_Poly1Projs);
l_minPoly2Proj = FMath::Min<float>(l_Poly2Projs);
l_maxPoly2Proj = FMath::Max<float>(l_Poly2Projs);
//UE_LOG(LogTemp, Warning, TEXT("MAX projetés de poly1 : %f"), l_maxPoly1Proj);
if (l_maxPoly1Proj < l_minPoly2Proj || l_maxPoly2Proj < l_minPoly1Proj) {
return false;
}
l_Poly1Projs.Empty();
l_Poly2Projs.Empty();
}
return true;
} |
Partager