Intersection between two lines
There are many useful functions in FMath to determine intersections e.g. between a line and a box, a line and a plane ... but not to calculate the intersection of two lines. Or is there one?
asked Jan 20 '16 at 09:20 PM in C++ Programming
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):
answered Jan 20 '16 at 10:09 PM
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..
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here