There are three points, A (x1, y1), B (x2, y2), C (x3, y3), you need to know if they belong to the same straight line, there is also an enum with types of functions, while there is only LINE, and there is also a functional interface in which there is a function method, and depending on the selected function, it is calculated whether the points belong to the same line, but there is a problem, I don’t know how to write the solution in java, here’s the code:

//functionType.java public enum functionType{ LINE } //Coordinates.java public class Coordinates{ private final int x, y; public Coordinates(int x, int y){ this.x = x; this.y = y; } public int getX(){ return x; } public int getY(){ return y; } //Вот в этом методе проблема: public boolean canMove(Coordinates point1, Coordinates point2, Coordinates point3, functionType type){ if(type == functionType.LINE){ Function function = (Coordinates point1, Coordinates point2, Coordinates point3) ->{ } } } //Function.java public interface Function{ public boolean function(Coordinates point1, Coordinates point2, Coordinates point3); } 

How to implement a method which in lambda expression? Thanks in advance!

  • e-maxx.ru/algo/segment_to_line for example. You can simply check the proportionality of the increments. - pavel
  • The problem is that this system is easy to solve in life, but in java I don’t know how, please code - Razor
  • one
    Pancake (x1-x2) / (y1-y2) = (x1-x3) / (y1-y3). Just write carefully. - pavel
  • @pavel I don’t want to bother, but the problem is that I don’t understand how to get a boolean from this equation) Sori for stupidity) - Razor

1 answer 1

@pavel I don’t want to bother, but the problem is that I don’t understand how to get a boolean from this equation) Sori for stupidity)

 return (x1-x2)*(y1-y3)==(x1-x3)*(y1-y2);