[Tutor] Questions of Maths

Abu Ismail abdulhafid at gmail.com
Thu Apr 19 13:05:07 CEST 2007


Thank you very much guys, this has been most helpful.

At the moment I run the program as Alan suggests. However, the goal is
to incorporate the program into Glade2 GUI and I am not sure that it
will work with Tk, although I must admit I have not tried it out yet.

Abu Ismail

On 4/18/07, János Juhász <janos.juhasz at velux.com> wrote:
> Hi Abu,
>
> > Question: how to determine whether point C is to the left or to the
> > right of the line AB?
>
> When the line given by A(Xa,Ya) and B(Xb, Yb),
> the area of the A-B-C triangle can be calculated with the value of next
> determinant / 2
>
> | Xa, Ya, 1 |
> | Xb, Yb, 1 |
> | Xc, Yc, 1 | / 2
>
> So:
>
> Area = ( Xa(Yb-Yc) - Xb(Ya-Yc) + Xc(Ya-Yb) ) / 2
>
> Area > 0 | the points are clockwise (C is on the left)
> Area < 0 | the points are counterclockwise (C is on the right)
> Area = 0 | the points are on the same line
>
>
> It can be written in a python function
>
> ###########
> def TriArea(a, b, c):
>     #Area = (Xa(Yb-Yc) - Xb(Ya-Yc) + Xc(Ya-Yb)) /2
>     return ( a[0] * (b[1]-c[1]) - b[0] * (a[1]-c[1]) + c[0] * (a[1]-b[1])
> )/2
>
> ###########
> # to test it.
> print TriArea((0,0), (10,0), (2,2))
> print TriArea((0,0), (10,0), (2,-2))
> print TriArea((0,0), (10,0), (2,0))
> ###########
>
>
> The biggest advantage of this calculation is that,
> it never goes to zero division exception.
>
>
>
> Best regards,
> Janos
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list