首页 > 编程知识 正文

如何求两点之间的斜率,如何求两点的斜率

时间:2023-05-05 23:09:45 阅读:194265 作者:2022

定义坐标实xxddy

public class Point {private double x; private double y; public Point(double x,double y){ this.x=x; this.y=y; } public double getX() { return x; } public void setX(double x) { this.x = x; } public double getY() { return y; } public void setY(double y) { this.y = y; }} public class Line {private Point point; private double slope; //斜率 public double getSlope() {return slope;}public void setSlope(double slope) {this.slope = slope;}public boolean isParallel(Line line) { //比较两个斜率是否相同 if(this.slope==line.slope)return true; return false; } public Line(Point point,double slope){ this.point=point; this.slope=slope; } public Line(Point p1,Point p2){ this(p1,p2.getY()-p1.getY()/(p2.getX()-p1.getX()));//调用上面的构造器,求得斜率 } public Line(int a,int b){ this(new Point(a,0),new Point(0,b)); } public static void main(String qjdxqargs){ Point p1 = new Point(1,1); Point p2 = new Point(2,2); Line l1=new Line(p1,p2); System.out.print(l1.getSlope()); }}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。