#Need help with finding the intercept in two lines
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
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.
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);
}
}```
Detected code, here are some useful tools:
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);
}
}
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);
}```
Detected code, here are some useful tools:
public void fixData() {
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);
}
Your maths looks wrong to me. Try doing it on paper first before you even try to write code.