Drawing triangles with java using trigonometry - java

What I'm trying to do is create a program which take a side length and two angles and produces a triangle drawn using the AWT library.
I'm having trouble working out the logic to use the trigonometric ratios to produce the x and y points of the polygon.
for example, given two angles and a side, I'm attempting to calculate the next x and y points to draw the lines to.
Currently, I've just got some arbitrary points defined to draw a triangle at the moment.
the code block below the graphics is the math for working out all the sides to the triangle
Could anybody be of assistance?
Here is my code. It is badly written. It's mostly just me experimenting and learning more about java.
import javax.swing.*;
import java.awt.*;
import java.math.*;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
public class program{
public static void main (String[] args) {
JFrame frame = new JFrame();
CustomPaintComponent c = new CustomPaintComponent();
frame.add(c);
frame.setSize(1000,1000);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setTitle("Triangle");
frame.setVisible(true);
}
}
class CustomPaintComponent extends Component {
public void paint(Graphics g){
Graphics2D G2D = (Graphics2D)g;
int[] xpoints = { 500, 750 , 1000 , 500};
int[] ypoints = { 500 , 250 , 500 , 500};
G2D.drawPolygon(xpoints,ypoints,4);
}
public Triangle calc(){
double s1,a1,a2;
s1 = Integer.parseInt(JOptionPane.showInputDialog("Please enter side 1"));
a1 = Integer.parseInt(JOptionPane.showInputDialog("Please enter angle 1"));
a2 = Integer.parseInt(JOptionPane.showInputDialog("Please enter angle 2"));
double s2 = ((s1/Math.sin(Math.toRadians(a1))) * Math.sin(Math.toRadians(a2)));
System.out.println(s1/Math.sin(a1));
System.out.println(Math.sin(a2));
double a3 = 180 - (a1 + a2);
double s3 = Math.pow(s2, 2) + Math.pow(s1, 2) - (2 * s2 * s1 * Math.cos(Math.toRadians(a3)));
s3 = Math.sqrt(s3);
Math.toDegrees(a1);
Math.toDegrees(a2);
Math.toDegrees(a3);
System.out.println("side 1 is " + s1 + "side 2 is " + s2 + " and the third angle is: " + a3 + " and the third side length is: " + s3);
Triangle Triangle = new Triangle(s1,s2,s3,a1,a2,a3);
return Triangle;
}
}
class Triangle{
double s1,s2,s3,a1,a2,a3;
Triangle(double s1, double s2, double s3, double a1, double a2, double a3){
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
}
}

The three rules that a triangle must satisfy:
The angles always add to 180°
A + B + C = 180 degrees
Law of Sines (The Sine Rule) a/sin(A) = b/sin(B) = c/sin(C)
Note: Angle A is opposite to side a, B is opposite to side b, and C is opposite to side c.
Law of Cosines (The Cosine Rule) c^2 = a^2 + b^2 − 2ab*cos(C)
So, let's say you have a triangle XYZ.
The angle opposite to side x = X (=YXZ), the angle opposite to side y = Y (=XYZ), and the angle opposite to side z = Z (=XZY).
The input given by the user is the two angles and the side in between them.
Let the input be:
Angle X = 76 degrees
Angle Y = 34 degrees
Side z = 9 cm
First, find the third angle Z by using the first property.
Angle Z = 180 - X - Y
= 180 - 76 - 34
= 70 degrees
Now, using the Law of Sines, find the sides x and y.
x/sin(X) = z/sin(Z)
=> x/sin(76°) = 9/sin(70°)
=> x = (9/sin(70°)) × sin(76°)
=> x = 9.29 cm
y/sin(Y) = z/sin(Z)
=> y/sin(34°) = 9/sin(70°)
=> y = (9/sin(70°)) × sin(34°)
=> y = 5.36 cm
To code it:
static void printSidesOfTriangle(double side3, double angle1, double angle2){
// The sum of all the angles of triangle is 180 degrees
double angle3 = 180 - angle1 - angle2;
// Converting the angles from degrees to radians
angle1 = Math.toRadians(angle1);
angle2 = Math.toRadians(angle2);
angle3 = Math.toRadians(angle3);
double ratio = side3/(Math.sin(angle3));
double side1 = ratio*(Math.sin(angle1));
double side2 = ratio*(Math.sin(angle2));
System.out.println("The sides of the traingle are: " +
String.valueOf(side1) + ", " +
String.valueOf(side2) + ", and " +
String.valueOf(side3) + ".");
}
And to get the x and y coordinates of each point of the triangle, you need to have some more information as there can be multiple triangles possible with 3 sides on a 2D plane.
Else, you may assume one of the coordinates to be (0,0) and find slopes of both sides.
This way, you will get the x and y coordinates of the remaining point as you have the lengths of these two segments.
Let's assume:
Angle X = 76 degrees
Angle Y = 34 degrees
Angle Z = 70 degrees
Side x = 9.29 cm
Side y = 5.36 cm
Side z = 9.00 cm
Assume three vertices to be (x1,y1), (x2,y2), and (x3,y3).
Check out this LINK
In this way, you can get the x and y coordinates of the remaining vertex.
To code it:
//printVerticesOfTriangle(5.35,9.29,9.0,34,76,70);
//printVerticesOfTriangle(3,4,5,37,53,90);
static void printVerticesOfTriangle(double side1, double side2, double side,
double angle1, double angle2, double angle3)
{
// side1 opposite to angle1
// side2 opposite to angle2
// side3 opposite to angle3
// The vertices are (x1,y1), (x2,y2) and (x3,y3)
double x1 = 0;
double y1 = 0;
double x2 = 0;
double y2 = 0;
double x3 = 0;
double y3 = 0;
// If an angle is 90 degrees, keep that vertex as the origin.
if(angle1==90){
x1 = 0;
y1 = 0;
x2 = side2;
y2 = 0;
x3 = 0;
y3 = side3;
}
else if(angle2==90){
x2 = 0;
y2 = 0;
x1 = side1;
y1 = 0;
x3 = 0;
y3 = side3;
}
else if(angle3==90){
x3 = 0;
y3 = 0;
x1 = side1;
y1 = 0;
x2 = 0;
y2 = side2;
}
// If it is not a right-angled triangle
else{
// Converting the angles from degrees to radians
angle1 = Math.toRadians(angle1);
angle2 = Math.toRadians(angle2);
// For the slope, angle with the positive x-axis is considered
angle3 = Math.toRadians(180-angle3);
x1 = 0;
y1 = 0;
x3 = side2;
y3 = 0;
// Vertex (x2,y2) has to be calculated
x2 = x3*Math.tan(angle3)/(Math.tan(angle1)-Math.tan(angle2));
y2 = x2*Math.tan(angle1);
}
System.out.println("The vertices of the triangle are: " +
"(" + String.format("%.2f",x1) + "," + String.format("%.2f",y1) + "), " +
"(" + String.format("%.2f",x2) + "," + String.format("%.2f",y2) + "), " +
"(" + String.format("%.2f",x3) + "," + String.format("%.2f",y3) + ")");
}

Related

Log-polar transform

I'm trying to perform a Log-polar transform on an image for the purpose of image registration. In other words I'm trying to achieve this:
------>
I need to code this from scratch in Java because I'll be doing this on the GPU side with OpenCL Java bindings and can't use libraries. There are multiple threads on this but none that could really help me, mostly because they're all using in-built MATLAB functions that I cannot replicate.
I've been trying the Polar Transform instead of the Log-Polar Transform for the sake of getting this to work because most info online refers to the first. So far, the best result I've had is with this bit here (pseudocode), based on this thread:
w = input.width; // Width of the input image
h = input.height; // Height of the input image
// Copy input pixels into an array
for(y=0; y<h; y++){
for(x=0; x<w; x++){
input[y*w+x] = getPixel(x, y);
}
}
// Polar transform
maxRadius = sqrt(w*w + h*h);
radiusScale = w / maxRadius;
angleScale = h / (2 * PI);
for(y=0; y<h; y++){
dy = y - h/2; // Distance from the center in the y-axis
for(x=0; x<w; x++){
dx = x - w/2; // Distance from the center in the x-axis
angle = atan2(dy, dx) % (2*PI);
radius = sqrt(dx*dx + dy*dy);
newY = radius * radiusScale;
newX = radius * thetaScale;
output[y*w+x] = input[newY*w+newX];
}
}
What I get resembles some sort of polar transformation, despite not being the result that I'm looking for:
output image
Can someone give me any pointers on this?
Thanks
EDIT:
The log-polar transform goes like .
EDIT:
Implementing #matt suggestions I now have the following code:
w = input.width; // Width of the input image
h = input.height; // Height of the input image
maxRadius = sqrt(w*w/4 + h*h/4);
radiusScale = h / maxRadius;
angleScale = w /PI/2;
offset = PI;
for(y=0; y<h; y++){
dy = y - h/2; // Distance from center in the y-axis
for(x=0; x<w; x++){
dx = x - w/2; // Distance from the center in the x-axis
angle = atan2(dy, dx);
radius = sqrt(dx*dx + dy*dy);
newY = radius * radiusScale;
newX = (angle + offset) * angleScale;
output[newY*w+newX] = input.getPixel(x, y);
}
}
Plotting the new output gives me this, which is still not what I expect to get.
One issue with this transform is that each "pixel" in the transformed space takes up a different amount of space in the x,y space. So here is how I am defining the transform.
Our new image will have the same dimensions
The Y axis will be 0 to Max Rho
The X axis will be -PI to +PI
So we start by iterating over the i,j coordinates of the output image. The resulting rho and theta are as follows.
double rho = j*maxRho / height;
double theta = i*maxTheta / width + offset;
Now we need to grab the input pixels at the respective location.
int x = (int) ( Math.exp(rho)*Math.cos(theta) + width/2);
int y = (int) ( Math.exp(rho)*Math.sin(theta) + height/2);
Now we can get the pixel value.
int pixel = input[y*width + x];
Your input variable is a bit redundante since you could just use your getPixel(x, y)
Then we just set the corresponding output value.
output[j*width + i] = pixel;
Here is a compilable example.
import javax.imageio.ImageIO;
import java.net.URL;
import java.awt.image.BufferedImage;
import java.io.File;
public class ScannerJunk{
public static void main(String[] args) throws Exception{
BufferedImage img = ImageIO.read( new URL("https://i.stack.imgur.com/MvDQT.png") );
BufferedImage out = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB );
double w = img.getWidth();
double h = img.getHeight();
double maxRho = 0.5*Math.log( w*w/4.0 + h*h/4.0 );
double maxTheta = 2 * Math.PI;
double offset = - Math.PI;
for(int i = 0; i< w; i++){
for(int j = 0; j< h; j++){
double rho = j*maxRho / h;
double theta = i*maxTheta / w + offset;
int x = (int) ( Math.exp(rho)*Math.cos(theta) + w/2);
int y = (int) ( Math.exp(rho)*Math.sin(theta) + h/2);
try{
out.setRGB( i, j, img.getRGB( x, y ) );
} catch(Exception e){
System.out.println( i + ", " + j + " :: " + rho + ", " + theta + " :: " + x + ", " + y );
}
}
}
ImageIO.write(out, "PNG", new File("transformed.png") );
}
}
Note that the max radius, does not map to the input image for all of the possible angles.
Also, the radius and theta axis appeat to be transposed from your example image.

Java geometry problem: perimeter of circular segment

Seq is a method which for given line: line's point a and slope b returns perimeter of circular segment. I used the equation of circle and line and solved it for x, and then I easily get two points. But instead of (3.5,1.9) approximately I get (6.528,0.0832000000000006)..
public class Circle {
Point center;
double r;
public double seq(Point a, double b) {
double n = -b*a.getX() + a.getY();
System.out.println("n: "+n);
if (r*r*(b*b+1)-Math.pow(b*center.getX()-center.getY()+n, 2) > 0) {
double temp = (1+b*b);
System.out.println("coeficient x^2: "+temp);
double temp1 = 2*((-1)*center.getX()+b*n-b*center.getY());
System.out.println("coeficient x: "+ temp);
double free_term = center.getX()*center.getX() + n*n -2*n*center.getY() + center.getY()*center.getY() - r*r;
System.out.println("free term: "+free_term);
double D = Math.sqrt(temp1*temp1-4*temp*free_term);
System.out.println(temp1*temp1-4*temp*free_term);
double x1 = ((-1)*temp1+Math.sqrt(temp1*temp1-4*temp*free_term))/2*temp;
double x2 = ((-1)*temp1-Math.sqrt(temp1*temp1-4*temp*free_term))/2*temp;
double y1 = b*x1 - b*a.getX() + a.getY();
double y2 = b*x2 - b*a.getX() + a.getY();
System.out.println("("+x1+","+y1+")"+", ("+x2+","+y2+")");
Point A = new Point(x1,y1);
Point B = new Point(x2,y2);
double d = A.dist(B);
System.out.println("d: "+d);
double angle = Math.acos((2*r*r-d*d)/2*r*r);
System.out.println("angle "+ alfa);
double l = r*Math.PI*angle/Math.toRadians(180);
return l+d;
} else return 0;
}
}
Main:
Circle k = new Circle();
Point c = new Point(0,0);
k.center = c;
k.r = 4;
Point a = new Point(0,4);
System.out.println(k.seq(a, -3.0/5.0));
Console:
n: 4.0
coeficient x^2: 1.3599999999999999
coeficient x: -4.8
free term: 0.0
23.04
(6.528,0.0832000000000006), (0.0,4.0)
d: 7.612890793910023
angleNaN
NaN
Your problem is in the implementation of the quadratic formula. You might think that A/2*B means A/(2*B) but in reality it's (A/2)*B. So add the parentheses in around the divisor:
double x1 = ((-1)*temp1+Math.sqrt(temp1*temp1-4*temp*free_term))/(2*temp);
double x2 = ((-1)*temp1-Math.sqrt(temp1*temp1-4*temp*free_term))/(2*temp);

Make Perlin noise with sharp edges

Hi so i am using the algorithm i found to generate perlin noise. What i want to do is create sharper edges with less curves Picture .
private static final double F2 = 0.5*(Math.sqrt(3.0)-1.0);
public float[][] generateSimplexNoise(int w, int h, double fre){
float [][]n = new float[w][h];
double f = fre /(float)w;
for(int i = 0; i < w ; i++){
for(int j = 0; j < h ; j++){
n[i][j] = (float) noise(i*f,j*f);
n[i][j] = (n[i][j]+1)/2; //CONVERTS TO 0-1 SCALE
}
}
return n;
}
// 2D simplex noise
public double noise(double xin, double yin) {
double n0, n1, n2; // Noise contributions from the three corners
// Skew the input space to determine which simplex cell we're in
double s = (xin+yin)*F2; // Hairy factor for 2D
int i = fastfloor(xin+s);
int j = fastfloor(yin+s);
double t = (i+j)*G2;
double X0 = i-t; // Unskew the cell origin back to (x,y) space
double Y0 = j-t;
double x0 = xin-X0; // The x,y distances from the cell origin
double y0 = yin-Y0;
// For the 2D case, the simplex shape is an equilateral triangle.
// Determine which simplex we are in.
int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
if(x0>y0) {i1=1; j1=0;} // lower triangle, XY order: (0,0)->(1,0)->(1,1)
else {i1=0; j1=1;} // upper triangle, YX order: (0,0)->(0,1)->(1,1)
// A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
// c = (3-sqrt(3))/6
double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
double y1 = y0 - j1 + G2;
double x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords
double y2 = y0 - 1.0 + 2.0 * G2;
// Work out the hashed gradient indices of the three simplex corners
int ii = i & 255;
int jj = j & 255;
int gi0 = permMod12[ii+perm[jj]];
int gi1 = permMod12[ii+i1+perm[jj+j1]];
int gi2 = permMod12[ii+1+perm[jj+1]];
// Calculate the contribution from the three corners
double t0 = 0.5 - x0*x0-y0*y0;
if(t0<0) n0 = 0.0;
else {
t0 *= t0;
n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
}
double t1 = 0.5 - x1*x1-y1*y1;
if(t1<0) n1 = 0.0;
else {
t1 *= t1;
n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
}
double t2 = 0.5 - x2*x2-y2*y2;
if(t2<0) n2 = 0.0;
else {
t2 *= t2;
n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
}
// Add contributions from each corner to get the final noise value.
// The result is scaled to return values in the interval [-1,1].
return 65.0 * (n0 + n1 + n2);
}
Having a noise lower than .25 classifies the block as brick and anything above .25 as grass.
Above is what i use to create the noise and convert it to a 0-1 scale. Any ideas/help with making the noise less curvy?
Looking at the image you linked to in the question the easiest solution is to sample at lower resolution and use a threshold filter to create the contrast you need.
double squareness = 50.0; // size of blocks values > 1 and in pixels
double threshold = 4; // number of levels
double pixVal;
// then inside the sampling loop
for(int i = 0; i < w ; i++){
for(int j = 0; j < h ; j++){
pixVal = noise(Math.floor(i / squareness) * squareness * f,
Math.floor(j / squareness) * squareness * f);
pixVal = pixVal / 2.0 + 0.5; // normalize
pixVal = Math.floor(pixVal * threshold) / thresholds;
n[i][j] = (float) pixVal; // put in array
}
}
You may wish to use a second noise function that you use to modify the squareness to reduce the regularity of boundaries
double sqrMin = 50.0; // min
double sqrMax = 150.0; // max
double thresholdSq = 4;
double threshold = 4;
double pixVal;
double square;
double scale = 1.0/3.0;
// then inside the sampling loop
for(int i = 0; i < w ; i++){
for(int j = 0; j < h ; j++){
square = noise(i * f * scale, i * j * scale) / 2.0 + 0.5;
square = Math.floor(square * thresholdSq) / thresholdSq;
square = square * (sqrMax - sqrMin) + sqrMin;
pixVal = noise(Math.floor(i / square ) * square * f,
Math.floor(j / square ) * square * f);
pixVal = pixVal / 2.0 + 0.5; // normalize
pixVal = Math.floor(pixVal * threshold) / thresholds;
n[i][j] = (float) pixVal; // put in array
}
}
If it looks good I do not know, its just a variation I thought of while adding the answer.

Calculating the area of a triangle

I am new to Java. I am trying to calculate the area of a triangle using the formula:
s = (side 1 + side 2 + side 3)/2
area = square root (side (side - side 1)(side - side2)(side - side3).
If the user enter the three point as:
1.5 -3.4 4.6 5 9.5 -3.4 then the area of the triangle should be 33.6. However, my program runs, but it's giving me an incorrect answer. Below is my code.
// Import Java Scanner
import java.util.Scanner;
import java.lang.Math;
public class Ex_2_19 {
public static void main(String[] args) {
//Create a Scanner object
Scanner input = new Scanner(System.in);
float side = 0;
float area1 = 0;
float area2 = 0;
float area3 = 0;
float area4 = 0;
float calculatedarea = 0;
//Prompt the user to enter three points of a triangle
System.out.println("Enter point x1:");
System.out.println("Enter point y1:");
System.out.println("Enter point x2:");
System.out.println("Enter point y2:");
System.out.println("Enter point x3:");
System.out.println("Enter point y3:");
//Define the variables
float Pointx1 = input.nextFloat();
float Pointy1 = input.nextFloat();
float Pointx2 = input.nextFloat();
float Pointy2 = input.nextFloat();
float Pointx3 = input.nextFloat();
float Pointy3 = input.nextFloat();
//Formula to calculate the area of a triangle
side = (Pointx1 + Pointy1 + Pointx2 + Pointy2 + Pointx3 + Pointy3) / 2;
area1 = side - (Pointx1 + Pointy1);
area2 = side - (Pointx2 + Pointy2);
area3 = side - (Pointx3 + Pointy3);
area4 = side * area1 * (area2) * (area3);
calculatedarea = (float) (Math.sqrt(area4));
//calculatedarea = (float) (Math.sqrt(area1)*(area2) * (area3));
//Print result
System.out.println("The area of the triangle is " + calculatedarea);
}
}
You are trying Heron's Formula - note that a, b, c are the euclidean distance between the points, thus will need to be computed by sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)), etc., not just the sum of differences.

How to detect overlapping circles and fill color accordingly?

I created 5 circles with random x and y coordinates and radii using 3 arrays (for x, y and radius size). However, I need the circles to dynamically change color based on whether or not they overlap with another circle. So if one of the 5 circles doesn't overlap at all, it should be colored black. Overlapping circles should be cyan. Two circles are considered to overlap if the distance between their center points is less than the sum of their radii.
This is what I have written so far for the circles class.
The following code will successfully draw the 5 circles in an applet window, and the distances are successfully calculated, but the problem is with the coloring. There's seems to be a logic error in the color filling and I don't see the problem here. Any suggestions? Thank you so much.
public class Circles extends Applet {
public void paint(Graphics page)
{
Random locator = new Random();
int [] xpt = new int [5];
int [] ypt = new int [5];
int [] rad = new int [5];
setPreferredSize (new Dimension(300, 300));
for (int i = 0; i < xpt.length; i++){
xpt[i] = locator.nextInt(100); //need to set a number or it goes into millions, cannot set it in Random()
ypt[i] = locator.nextInt(100);
rad[i] = locator.nextInt(100);
System.out.println("The #" + i + " x-point: " + xpt[i] + " y-point: " + ypt[i] + " radius: " + rad[i]); //for debugging purposes
for (int j = 0; j < xpt.length; j++){
double xpoint1 = xpt[i]+rad[i];
double ypoint1 = ypt[i]+rad[i];
double xpoint2 = xpt[j]+rad[j];
double ypoint2 = ypt[j]+rad[j];
double radius1 = rad[i];
double radius2 = rad[j];
double theDistance = distance(xpoint1,ypoint1,xpoint2,ypoint2);
System.out.println("Comparing " + i + " to " + j); //for debugging and logic checking
if (i==j)
;
else if (theDistance <= (radius1+radius2))
{
page.setColor(Color.cyan);
page.fillOval(xpt[i], ypt[i], rad[i], rad[i]);
//page.fillOval(xpt[j], ypt[j], rad[j], rad[j]);
System.out.println("Overlap occurred. Colored " + i + " and " + j + " cyan.");
System.out.println("Center points: ("+ xpoint1 +", "+ ypoint1 +") and ("+ xpoint2 + ", "+ ypoint2 + ").");
}
else
{
page.setColor(Color.black);
page.fillOval(xpt[i], ypt[i], rad[i], rad[i]);
//page.fillOval(xpt[j], ypt[j], rad[j], rad[j]);
System.out.println("No overlap. Made " + i + " and " + j + " black.");
}
}
}
}
public static double distance(
double x1, double y1, double x2, double y2) {
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
}
The xpoint, ypoint, etc. lines are not doing what you think.
If you want to find if two circles are overlapping, you need to find if the distance between the centers of the circles is greater or less than the sum of their radii.
So:
function circlesCollide(x1, y1, r1, x2, y2, r2){
return (distance(x1, y1, x2, y2) <= (r1 + r2));
}
Why do you +rad[] here? You don't have to add the radius for comparing the distance.
double xpoint1 = xpt[i]+rad[i];
double ypoint1 = ypt[i]+rad[i];
double xpoint2 = xpt[j]+rad[j];
double ypoint2 = ypt[j]+rad[j];
[...]
double theDistance = distance(xpoint1,ypoint1,xpoint2,ypoint2);
[...]
page.fillOval(xpt[i], ypt[i], rad[i], rad[i]);
You should use xpt / ypt for the distance. not xpoint1, and use - for value and 2 * radius for size ...... i.e.:
double xpoint1 = xpt[i]-rad[i];
double ypoint1 = ypt[i]-rad[i];
double xpoint2 = xpt[j]-rad[j];
double ypoint2 = ypt[j]-rad[j];
[...]
double theDistance = distance(xpt[i],ypt[i],xpt[j],ypt[j]);
[...]
page.fillOval(xpoint1 , ypoint1, 2*rad[i], 2*rad[i]);

Categories