Find if a point is within a triangle: Difference between revisions

Content added Content deleted
(Added Common Lisp)
Line 283: Line 283:
; We use the sign of the determinant of vectors (AB,AM), where M(X,Y) is the query point:
; We use the sign of the determinant of vectors (AB,AM), where M(X,Y) is the query point:
; position = sign((Bx - Ax) * (Y - Ay) - (By - Ay) * (X - Ax))
; position = sign((Bx - Ax) * (Y - Ay) - (By - Ay) * (X - Ax))
(sign (- (* (- (car B) (car A))
(signum (- (* (- (car B) (car A))
(- (cdr P) (cdr A)) )
(- (cdr P) (cdr A)) )
(* (- (cdr B) (cdr A))
(* (- (cdr B) (cdr A))
(- (car P) (car A)) ))))
(- (car P) (car A)) ))))



(defun sign (x)
(if (plusp x)
1
(if (minusp x)
-1
0 )))
</lang>
</lang>
{{out}}
{{out}}
Line 313: Line 306:
NIL
NIL
</pre>
</pre>




=={{header|D}}==
=={{header|D}}==