Draw circles at end Point of Line with End Points as Centre

In summary, the conversation was about trying to draw circles at the end points of a line using the drawOval() method in Java. The issue was that the center of the circle appeared to be slightly off from the end point of the line. The solution was to adjust the coordinates to take into account the width and height of the oval.
  • #1
zak100
462
11
Hi,

I am trying to draw circles at the end points of a line but circle centre is not exactly on the end point of the line. Can somebody please guide me.

import java.applet.Applet;

import java.awt.*;

import javax.swing.*;

public class JCircle extends Applet{

int x1=30;

int y1=30;

int x2=60;

int y2=60;

public void paint(Graphics g) {

g.drawLine(x1, y1,x2, y2);

g.drawOval( x1, y1, 10, 10);

g.drawOval( x2, y2, 10, 10);



}

}

Some body please guide me.

Zulfi.
 

Attachments

  • circles not at end points.jpg
    circles not at end points.jpg
    1,003 bytes · Views: 477
Technology news on Phys.org
  • #2
Perhaps drawoval doesn't do what you think it does ? Looks to me as if the top left corner appears at (x,y) , not the center...
 
  • #3
BvU said:
Perhaps drawoval doesn't do what you think it does ? Looks to me as if the top left corner appears at (x,y) , not the center...
From the documentation for the drawOval() method - ()
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#drawOval(int said:
public abstract void drawOval(int x,
int y,
int width,
int height)
Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by the x, y, width, and height arguments.
The oval covers an area that is width + 1 pixels wide and height + 1 pixels tall.

Parameters:
x - the x coordinate of the upper left corner of the oval to be drawn.
y - the y coordinate of the upper left corner of the oval to be drawn.
width - the width of the oval to be drawn.
height - the height of the oval to be drawn.
@zak100, please use code tags on your code. They should look like this:
[code=java]
Java:
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
public class JCircle extends Applet
{
    int x1=30;
   // etc.
[/code]
 

FAQ: Draw circles at end Point of Line with End Points as Centre

1. What is the purpose of drawing circles at the end points of a line?

The purpose of drawing circles at the end points of a line is to mark the exact end points and create a visual representation of the line's length and direction.

2. How do you determine the radius of the circles at the end points?

The radius of the circles at the end points can be determined by measuring the distance from the end point to the center of the circle, which is the same as the length of the line.

3. Can the circles be drawn at any angle?

Yes, the circles can be drawn at any angle as long as the end points of the line are used as the center of the circles.

4. Is this method only applicable to straight lines?

No, this method can be used for any type of line, including curves, as long as the end points are clearly defined.

5. What are the practical applications of drawing circles at the end points of a line?

This method is commonly used in geometry and engineering for precise measurements and visual representations of lines and their end points. It can also be used in art and design for creating symmetrical and balanced compositions.

Similar threads

Replies
6
Views
1K
Replies
1
Views
1K
Replies
5
Views
6K
Replies
1
Views
2K
Replies
2
Views
1K
Replies
4
Views
2K
Replies
3
Views
4K
Back
Top