Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Does a triangle contain the origin?

  • 23-05-2010 8:08pm
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    I'm trying to do this puzzle from project euler, wondering could someone tell me if the method i'm trying is wrong?

    I'm not looking for an answer, just maybe an example of when it wouldn't work?

    Basically I was saying for the triangle ABC, look to see if the intersect of the line from A to the Origin and the line BC are both in the same quadrant, then the same for the other three points. If any of them show up in the same quadrant then it doesn't contain the origin.

    Could this method work?


Comments

  • Closed Accounts Posts: 201 ✭✭ArmCandyBaby


    What two points specifically lie in the same quadrant? The intersection of the lines AO and BC and what other point? I might be missing something here but I don't think this method will work.


  • Registered Users, Registered Users 2 Posts: 360 ✭✭CJC86


    Yeah, I don't quite understand your method either, but it doesn't sound correct.

    If you form the equation of the line AB, then you can check if C and the origin are on the same side of the line by plugging them into the equation, and seeing if the results are both positive or both negative. I think this is what you need to use.


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭gerry87


    I probably didn't explain it very well... time for pictures!

    Basically I was thinking that if the line from any point to the origin, crosses the line between the other two points in the same quadrant as itself, then it can't contain the origin.

    If all the points are around the origin, then for example it would look like this, so the red point is in a different quadrant to B
    HgU93.png

    On the other hand, if the triangle doesn't contiain the origin then the red point would be in the same quadrant as B
    vTjz4.png

    Is that clearer?

    I can't think of any examples of a case where it wouldn't work, but i'm not getting the right answe so I'm not sure is it my code or method.


  • Closed Accounts Posts: 201 ✭✭ArmCandyBaby


    Yeah that looks OK I think but remember to include the code where the intersection of AO and BC lies outside either B or C because they could be in different quadrants and still not contain the origin.


  • Registered Users, Registered Users 2 Posts: 13,077 ✭✭✭✭bnt


    My first instinct is to work with the angles, from each vertex to the other two points and the origin, expressed in terms of absolute bearing. If the bearing to the origin is between the bearings to the other two points, in the case of all three vertices, then the origin must be inside the triangle. Let me fire up Gnumeric and we'll see ... it might be sufficient to do this for any two vertices, rather than all three?

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Advertisement
  • Registered Users, Registered Users 2 Posts: 338 ✭✭ray giraffe


    gerry87 wrote: »
    I probably didn't explain it very well... time for pictures!

    Basically I was thinking that if the line from any point to the origin, crosses the line between the other two points in the same quadrant as itself, then it can't contain the origin.

    If all the points are around the origin, then for example it would look like this, so the red point is in a different quadrant to B
    HgU93.png

    On the other hand, if the triangle doesn't contiain the origin then the red point would be in the same quadrant as B
    vTjz4.png

    Is that clearer?

    I can't think of any examples of a case where it wouldn't work, but i'm not getting the right answe so I'm not sure is it my code or method.

    Method looks good to me. Check you have dealt properly with special cases - where the origin is on an edge of the triangle, or the origin is a vertex.
    bnt wrote: »
    My first instinct is to work with the angles, from each vertex to the other two points and the origin, expressed in terms of absolute bearing. If the bearing to the origin is between the bearings to the other two points, in the case of all three vertices, then the origin must be inside the triangle. Let me fire up Gnumeric and we'll see ... it might be sufficient to do this for any two vertices, rather than all three?

    Sufficient for two vertices I think. Would be more computationally expensive that the OP's solution, I believe.


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭gerry87


    Cheers guys, got the answer. Kinda cheated with the special cases ray mentioned, there was only one special case so I got it to print it out and did it by hand, ah well!


Advertisement