#Need help with finding the intercept in two lines

1 messages · Page 1 of 1 (latest)

paper perch
#

Need a better formula

brisk lilyBOT
#

<@&987246399047479336> please have a look, thanks.

brisk lilyBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

paper perch
#
            MyPoint p1 = new MyPoint(input1, input2);
            MyPoint p2 = new MyPoint(input3, input4);
            MyLine L1 = new MyLine(p1, p2);
            p1 = new MyPoint(input5, input6);
            p2 = new MyPoint(input7, input8);
            MyLine L2 = new MyLine(p1, p2);
            if(L1.getSlope()==L2.getSlope()) {
                System.out.println("The lines do not intersect.");
            }
            else {
            double x = (L2.getYInt() - L1.getYInt()) / (L2.getSlope()-L1.getSlope());
            double y = L1.getSlope() * (x + L1.getYInt());
            String intersection = String.format("The lines intersect at point (%.3f,%.3f)", x,y);
            System.out.println(intersection);
            }
        }```
brisk lilyBOT
# paper perch ```if (choice==5) { MyPoint p1 = new MyPoint(input1, input2); ...

Detected code, here are some useful tools:

Formatted code
if (choice == 5) {
  MyPoint p1 = new MyPoint(input1, input2);
  MyPoint p2 = new MyPoint(input3, input4);
  MyLine L1 = new MyLine(p1, p2);
  p1 = new MyPoint(input5, input6);
  p2 = new MyPoint(input7, input8);
  MyLine L2 = new MyLine(p1, p2);
  if (L1.getSlope() == L2.getSlope()) {
    System.out.println("The lines do not intersect.");
  }
  else {
    double x = (L2.getYInt() - L1.getYInt()) / (L2.getSlope() - L1.getSlope());
    double y = L1.getSlope() * (x + L1.getYInt());
    String intersection = String.format("The lines intersect at point (%.3f,%.3f)", x, y);
    System.out.println(intersection);
  }
}
paper perch
#

MyLine class where slope, b, xint and yint is calculated

       slope = (p2.getY() - p1.getY()) / (p2.getX() - p1.getX());
       double b = p1.getY() - slope * p1.getX();
       xint = (0 - b) / (slope * 1.0);
       yint = (slope * 0 + b);
   }```
brisk lilyBOT
lunar rampart