Results 1 to 4 of 4
  1. #1
    jakeob22 is offline Member
    Join Date
    May 2014
    Posts
    8
    Rep Power
    0

    Default Is this random coordinate inside of the triangle?

    I'm having a random x and y coordinate generate and I need to check if the coordinates are inside of a right triangle on this imaginary coordinate plane:
    Is this random coordinate inside of the triangle?-right-triangle.png

    If anybody could give me some if statements to use to find if it is within the triangle, I'd be really happy. Thank you!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,646
    Rep Power
    5

    Default Re: Is this random coordinate inside of the triangle?

    Well, we don't provide code here (except to illustrate general concepts). To solve your problem you first need to figure out how you would do it on paper. You clearly know the height and the width of the triangle. So all you need to worry about is whether it is below the hypotenuse and above the base. So x should be easy. Once you have x, then think about the equation of a straight line to determine y. Once you figure it out on paper, it should be trivial to translate into Java.

    Note: The approach above assumes at least one of the two shorter sides is parallel to the x-axis.

    Regards,
    Jim
    Last edited by jim829; 05-24-2014 at 03:39 AM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    jakeob22 is offline Member
    Join Date
    May 2014
    Posts
    8
    Rep Power
    0

    Default Re: Is this random coordinate inside of the triangle?

    Quote Originally Posted by jim829 View Post
    Well, we don't provide code here (except to illustrate general concepts). To solve your problem you first need to figure out how you would do it on paper. You clearly know the height and the width of the triangle. So all you need to worry about is whether it is below the hypotenuse and above the base. So x should be easy. Once you have x, then about the equation of a straight line to determine y. Once you figure it out on paper, it should be trivial to translate into Java.

    Note: The approach above assumes at least one of the two shorter sides is parallel to the x-axis.

    Regards,
    Jim
    Thanks Jim, it's my first post and I wasn't aware that you didn't provide code. I'm glad you don't provide it because it forces people to think. I get the idea of what you're saying, thanks! :D

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,646
    Rep Power
    5

    Default Re: Is this random coordinate inside of the triangle?

    You're welcome. And once you try and code it in Java, we can certainly help you with any syntactic or even logic problems you may encounter.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. coordinate converter
    By footballxpaul in forum New To Java
    Replies: 15
    Last Post: 03-20-2014, 08:03 PM
  2. Replies: 1
    Last Post: 06-14-2013, 04:00 PM
  3. Replies: 2
    Last Post: 04-10-2010, 06:35 PM
  4. Replies: 3
    Last Post: 02-07-2010, 08:34 PM
  5. Random Points inside a Polygon
    By nidhirastogi in forum Advanced Java
    Replies: 1
    Last Post: 09-23-2008, 03:28 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •