Jump to content
• Advertisement

# Two points and a point inside

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hello all . My name is Cordel and I would appreciate your help with the following problem. I have two points (x1,y1) (x2,y2) and one more point N(a,b) and I need to check whether or not the point N is inside the rectangle that has been made by the first two points. I've tried a few ways to solve that problem but came up empty handed. Any suggestions ? Thankx in advance

#### Share this post

##### Share on other sites
Advertisement
You mean its x coordinate should be in between x1 and x2, and its y coordinate should be in between y1 and y2?

O, and don't cross post please.

#### Share this post

##### Share on other sites
Moving to Math and Physics as there's no Java related in this thread.

#### Share this post

##### Share on other sites
I mean that if you take P1 and P2 (the 1st two points) and put them on a diagonal line ,you would get a rectangle (the points cannot by on an horizontal line or vertical line - only diagonal) .

Now ,let us take N(a,b) and put it inside the rectangle that has been made.
I need to check whether N is inside or not .

Sorry for not mentioning it before !!!

edit :

BTW I've tried using dot-product but didn't succeed,and therefore I'm looking for other ideas.

#### Share this post

##### Share on other sites
Reread WanMasters reply.

#### Share this post

##### Share on other sites
I've read it.

You mean maybe to substract each two dots (x1 and x2 ,y1 and y2) and somehow comapare it with (a,b) ?

#### Share this post

##### Share on other sites
Quote:
 Original post by cordelI've read it.You mean maybe to substract each two dots (x1 and x2 ,y1 and y2) and somehow comapare it with (a,b) ?

No, that wouldn't work.

Just check whether x1 <= a <= x2 and y1 <= b <= y2 (after making sure x1 <= x2 and y1 <= y2 by swapping the coordinates around accordingly if necessary).

#### Share this post

##### Share on other sites
Thank you everyone for the help !!

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5
• Advertisement

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013431
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!