0

I want to find the point in between four points or not. Please help me, is there any algorithm?? I want to write in java program.

Thanks, Nitin

Chris
  • 7,579
  • 3
  • 18
  • 38
Nitin Karale
  • 789
  • 3
  • 12
  • 34
  • What do you mean exactly by "the point in between four points or not"? Are you referring to the intersection of the diagonals? – Alex Barac May 27 '14 at 07:57
  • 4
    Use maths! First try to solve the mathematic problem (with pencil & paper) and finally try to convert it to code. – Christian Tapia May 27 '14 at 07:57

2 Answers2

2

You can use java.awt.Polygon.

public boolean contains(Point p)

Checks whether or not this Polygon contains the specified Point. It's algorithm is pretty fast. If you need an even faster approach, read this.

sina72
  • 4,931
  • 3
  • 35
  • 36
0

Lets say you have a rectangle called r, this r has an x position, y position, width and height.

The middle would be :

Point p = new Point(r.x + (r.width / 2), r.y + (r.height / 2));

To check if the point is inside the rectangle

if(p.x >= r.x && p.y >= r.y && p.x <= r.x + r.width && p.y <= r.y + r.height){
     //The point is inside the rectangle
} 

To check if the point is inside the four points if the points where layed out like this :

   A  B
   C  D

   if(p.x >= a.x && p.y >= a.y && p.x <= b.x && p.y <= d.y){
         //The point is inside the points
   }
thetheodor
  • 248
  • 2
  • 22