I am drawing lines using drawLine
method in Java. I know beginning and end points of lines.
BufferedImage
whose width and height are determined by Dimension(500,500)
, do the points which determine the start and the end of a line correspond to the pixels? Then will calculating only the distance of two points be sufficient for measuring the pixel length of line?答案 0 :(得分:1)
BufferedImage
以整数形式工作;笛卡尔空间。所以每个像素对应一个点。
如果您有积分,请使用distance formula确定长度。
int distance = (int) Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
如果您使用Point2D
课程作为积分,有多种方法可以让您更轻松地确定距离。
double distance(double px, double py)
static double distance(double x1, double y1, double x2, double y2)
double distance(Point2D pt)
double distanceSq(double px, double py)
static double distanceSq(double x1, double y1, double x2, double y2)
double distanceSq(Point2D pt)