作业帮 > 综合 > 作业

java 怎么判断一个点是否位于一个图形的边界上,比如是否在一条线上?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/28 01:57:44
java 怎么判断一个点是否位于一个图形的边界上,比如是否在一条线上?
graphics对象画出来的图形好像不能判断是否包含一个点,我要做一个画图程序,怎么才能知道一个点是否在画出来的图形的边界上?
使用Shape类.Graphics/Graphics2D的 draw(shape)这个方法.
Shape有contains方法判断
boolean
contains(double x,
double y)
Tests if the specified coordinates are inside the boundary of the
Shape, as described by the

definition of insideness.

boolean
contains(double x,
double y,
double w,
double h)
Tests if the interior of the Shape entirely contains
the specified rectangular area.

boolean
contains(Point2D p)
Tests if a specified Point2D is inside the boundary
of the Shape, as described by the

definition of insideness.

boolean
contains(Rectangle2D r)
Tests if the interior of the Shape entirely contains the
specified Rectangle2D.
再问: shape怎么定义一个圆啊。。。就比如要用 Shape []shape= new Shape[5] draw(shape[0])画一个圆,那应该怎么定义这个shape[0]啊
再答: Ellipse2D 这个椭圆类用来画圆shape[0] = new Ellipse2D.Double(0,0,30,30);