Plot Points randomly
package positioning;
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
public class Positioning extends JPanel
{
static List<Point> list = new ArrayList<Point>();
static List<Points> intersection = new ArrayList<Points>();
static int MAX = 30, r = 30;
public static void getcoordinates()
{
int x, y, count = 0;
Random r;
Point p;
while(count < MAX)
{
r = new Random();
x = [Link](500) + 1;
y = [Link](500) + 1;
p = new Point(x, y);
[Link](p);
count++;
}
while((--count) >= 0)
[Link]((int)[Link](count).getX() + " " +
(int)[Link](count).getY());
}
static void getIntersectionPoints()
{
int i, j, count;
Point p1, p2;
Points i1, i2;
double R, l, h, x1, x2, y1, y2, d, m, xm, ym;
for(i = 0; i < MAX-1; i++)
{
p1 = [Link](i);
for(j = i+1; j < MAX; j++)
{
p2 = [Link](j);
//[Link](i + " " + j);
d = [Link]([Link]([Link]() - [Link](), 2) +
[Link]([Link]() - [Link](), 2));
if(d-r >= 0 && d-(2*r) <= 0)
{
xm = ([Link]() + [Link]()) / 2;
ym = ([Link]() + [Link]()) / 2;
m = ([Link]() - [Link]())/([Link]() - [Link]());
//Slope
h = [Link]((4*r*r) - (d*d))/2;
x1 = xm + (m * h)/[Link](1 + (m*m));
x2 = xm - (m * h)/[Link](1 + (m*m));
y1 = ym - h/[Link](1+(m*m));
y2 = ym + h/[Link](1+(m*m));
[Link](new Points((int)[Link](x1)-1, (int)[Link](y1)-1, (int)[Link](x2)-
1, (int)[Link](y2)-1));
}
}
}
[Link]("INTERSECTION POINTS : ");
count = [Link]();
while((--count) >= 0)
{
i1 = [Link](count);
[Link](i1.getX1() + " " + i1.getY1() + " " + i1.getX2() + " " +
i1.getY2());
}
}
public void paintComponent(Graphics g)
{
[Link](g);
Graphics2D g2D = (Graphics2D)g;
Point p;
Points p1;
int x, y;
[Link](0, 0, 570, 0);
[Link](570, 0, 565, 5);
[Link](0, 0, 0, 565);
[Link](0, 565, 5, 560);
//To display the points in the 2D-Plane
for(int i = 0; i < [Link](); i++)
{
p = [Link](i);
x = (int)[Link]();
y = (int)[Link]();
[Link](x, y, 4, 4);
[Link](x-r, y-r, 2*r, 2*r);
}
//To find the intersection of the circles
for(int i = 0; i < [Link](); i++)
{
p1 = [Link](i);
[Link]([Link]);
[Link](p1.getX1(), p1.getY1(), 3, 3);
[Link](p1.getX2(), p1.getY2(), 3, 3);
[Link](p1.getX1(), p1.getY1(), p1.getX2(), p1.getY2());
}
}
public static void main(String args[])
{
getcoordinates();
getIntersectionPoints();
[Link](new Runnable() {
public void run()
{
JFrame f = new JFrame("POINTS PLOTTING");
[Link]().add(new Positioning());
[Link](JFrame.EXIT_ON_CLOSE);
[Link](600, 600);
[Link](true);
}
});
}
}
Points class
package positioning;
import [Link];
public class Points
{
int x1, y1, x2, y2;
Points() {}
Points(int x1, int y1,int x2, int y2)
{
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
Points getPoint()
{
return this;
}
void setPoints(int x1, int y1,int x2, int y2)
{
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
int getX1()
{
return this.x1;
}
int getX2()
{
return this.x2;
}
int getY1()
{
return this.y1;
}
int getY2()
{
return this.y2;
}
}