Considering the points p0x, p0y, p1x and p1y, in addition to their relationships,
deltaX = (p1x-p0x)
and
deltaY = (p1y - p0y).
Devise a way to draw a line on an image, at any possible inclination. I want make this using JFrame
but I don't now how to make this:
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class Template extends JFrame {
private BufferedImage img;
public Template() {
img = new BufferedImage(1600, 1200, BufferedImage.TYPE_INT_RGB);
setBounds(10,10,1600,1200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Template");
drawLine();
setVisible(true);
}
private void drawLine(int p0x,int p0y, int p1x ,int p1y) {
p0x = 50;
p0y = 50;
p1x = 200;
p1y = 200;
int deltaX = (p1x-p0x);
int deltaY = (p1y - p0y);
}
@Override
public void paint(Graphics g) {
g.drawImage(img, 0, 0, this);
}
public static void main(String[] args) {
Template t = new Template();
}
}
An algorithm to make a line in any possible inclination.