I’ve been working on a project that requires me to fit a grid with a certain number of squares into a given screen size. I find the optimal ratio for the grid by finding all the factors of the number of squares, and comparing the ratio of those factors to the aspect ratio of the screen. In the event that the closest ratio I can get from the squares is too far for my liking, I want to use a system of equations to find the best ratio I can get, even if I have to remove squares.
Here are the equations I want to use:
width × height = number of squares
width ÷ height = aspect ratio
This is a visual of the graph, and I want to find the coordinates of the intersection.
Visual representation of graph
Finding the intersection of these lines and rounding down should give me a reasonably close ratio for the grid. However, I do not know how to find where these lines intersect in Java, and all the solutions I’ve found only work when both equations are linear. Can anyone help with this?
Israel Emmanuel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.