# Thread: Calculating the intersecting points of a line on two squares

1. ## Calculating the intersecting points of a line on two squares

Hi guys,
I've got an interesting math problem that I'm struggling to solve. It's a little complicated to explain, but essentially it is this:

Given a point P that is contained by the convex hull of the squares A & B (A & B do not overlap).
A line intersects A at point PA, B at point PB, and point P; such that the ratio [distance from PA to P] : [distance P to PB] must be as large as possible (PA to P being larger).

Calculate points PA and PB.

I'm not really sure how to calculate this, but if anyone could point me in the right direction I would be very grateful!

2. ## Re: Calculating the intersecting points of a line on two squares

Hey Saifa.

This sounds like a standard optimization problem where you are maximizing distance. The first thing you should do is convert the problem to a set of equations and inequalities.

Do you have a definition for lines A and B in terms of all the points?

3. ## Re: Calculating the intersecting points of a line on two squares

Hi Chiro,

Nope, I don't know any equations for the polygons or lines.
I just have a list of 4 points for the two squares and I know the x and y coordinate of all points.

so if I use the line equation:

ax + by + c = 0

given that it goes through the point:

PX, PY

Can I calculate any line that goes through P and work out the best gradient later?

I have no clue on what to do after this point, would I represent a square as an equation?