• API
• FAQ
• Tools
• Archive
daily pastebin goal
57%
SHARE
TWEET

# Untitled

a guest Jun 19th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2. public class Line
3. {
4.    private static double EPSILON=1E-14;
5.    private double cx1;
6.    private double cy1;
7.    private double cx2;
8.    private double cy2;
9.    private double m;
10.    private double cb;
11.    private double ca;
12.
13.    //When (x,y) and m are given
14.    public Line(double x1, double y1, double slope)
15.    {
16.       //Sets the variables
17.       cx1=x1;
18.       cy1=y1;
19.       m=slope;
20.
21.       //Finds b for y=mx+b
22.       cb=(cx1*m)-y1;
23.    }
24.
25.    //When (x1, y1) and (x2, y2) are given
26.    public Line(double x1, double y1, double x2, double y2)
27.    {
28.       //Sets the variables
29.       cx1=x1;
30.       cy1=y1;
31.       cx2=x2;
32.       cy2=y2;
33.
34.       //Finds the slope
35.       m=(cy2-cy1)/(cx2-cx1);
36.
37.       //Finds b for y=mx+b
38.       cb=(cx1*m)-y1;
39.    }
40.
41.    //When y=mx+b is given
42.    public Line(double slope, double b)
43.    {
44.       //Sets the variables
45.       m=slope;
46.       cb=b;
47.
48.    }
49.
50.    //When x=a is given for vertical lines
51.    public Line(double a)
52.    {
53.       //Sets the variables
54.       ca=a;
55.
56.       //Slope and y intercept are zero, since it's vertical
57.       m=0;
58.       cb=0;
59.
60.    }
61.
62.
63.    public boolean intersects(Line other)
64.    {
65.       if(Math.abs(m-other.m) > EPSILON)
66.          return true;
67.       else
68.          return false;
69.    }
70.
71.    public boolean equals(Line other)
72.    {
73.       if((Math.abs(m-other.m) < EPSILON) && (Math.abs(cb-other.cb) < EPSILON))
74.          return true;
75.       else
76.          return false;
77.    }
78.
79.    public boolean isParallel(Line other)
80.    {
81.       if(Math.abs(m-other.m) < EPSILON)
82.          return true;
83.       else
84.          return false;
85.    }
86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top