Answers for "Intersection between two lines"
https://answers.unrealengine.com/questions/363361/intersection-between-two-lines.html
The latest answers for the question "Intersection between two lines"Answer by DennisDing
https://answers.unrealengine.com/answers/476099/view.html
This method is right basically...But there are some point that may haven't be considered...
if (res >= 0.0f && res <= 1.0f)
This condition can not include all the situation..
For example...
Line a and line b will not intersect..Just like the picture i give below...But it will return true.Because the cross point is on line a.
In order to make it right,it must consider if the intersect point is on line b too...
What's more ,I found some different from your answer and the answer on github...
On github,the answer is
float res = FVector::DotProduct(FVector::CrossProduct(dc, db), FVector::CrossProduct(da, db)) / prod;
Your answer is
float res = FVector::DotProduct(FVector::CrossProduct(dc, db), FVector::CrossProduct(da, db) / prod);
There are some different about ")"...
I havn't test which one is right .But I'm using the github answer and it looks right...
Thanks for the solution you provides. It helps me a lot.
![alt text][1]
[1]: /storage/temp/104390-1.pngFri, 26 Aug 2016 06:55:26 GMTDennisDingAnswer by padmalcom
https://answers.unrealengine.com/answers/363384/view.html
For all those who are interested I found a working solution here https://gist.github.com/hanigamal/6556506 and implemented a simple function for UE (I only did 2 tests for the method):
bool PCGUtils::lineToLineIntersection(const FVector& fromA, const FVector& fromB, const FVector& toA, const FVector& toB, FVector& _outIntersection)
{
FVector da = fromB - fromA;
FVector db = toB - toA;
FVector dc = toA - fromA;
if (FVector::DotProduct(dc, FVector::CrossProduct(da, db)) != 0.0) {
return false;
}
FVector crossDaDb = FVector::CrossProduct(da, db);
float prod = crossDaDb.X * crossDaDb.X + crossDaDb.Y * crossDaDb.Y + crossDaDb.Z * crossDaDb.Z;
float res = FVector::DotProduct(FVector::CrossProduct(dc, db), FVector::CrossProduct(da, db) / prod);
if (res >= 0.0f && res <= 1.0f) {
_outIntersection = fromA + da * FVector(res, res, res);
return true;
}
return false;
}Wed, 20 Jan 2016 22:09:53 GMTpadmalcom