employer cover photo
employer logo
employer logo

Susquehanna International Group

Employeur impliqué

Question d’entretien chez Susquehanna International Group

Write a function to determine whether a point lies within a triangle (2D space).

Réponses aux questions d'entretien

Utilisateur anonyme

2 déc. 2010

I knew how to do this in 3D because I'd done it numerous times before, but my mind panicked and blanked and I couldn't figure out how to step back to 2D. I ended up doing it in 3D, which confused them but they let it slide. Basically, if you had triangle a,b,c and point p, you check to see if point p lies on the same side of each line (e.g. ab) as the third point (e.g. c). I did this by setting the z value of all vectors to 0 (since it was 2D space), taking the cross products abxap and abxac (for example) and seeing if the resulting vectors' z values had the same sign (both negative or both positive). There's a better way to do it in 2D though.

Utilisateur anonyme

11 mai 2012

Let the triangle is abc and the point is p. Then calculate the area of the three triangles abp, acp and bcp. if the sum is not equal to the area of abc then the point is outside.

1

Utilisateur anonyme

22 oct. 2020

niubi answer