# help with distance formula when converting line equation in bisector form to implicit form

This topic is 1054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working my way through 3D Math Primer for Graphics and Game development 2nd edition and have a question about the following step at the end of section 9.2.3.

Can someone decipher what the following is doing for me?

d=(q+r)/2 dot [a b]

More details

The method starts off assuming you have a line defined as follows

distance(p,q) = distance(p,r)

where q and r are points that anchor the line such that the line is all points equidistant from q and r.

Towards converting this to implicit form, ax+by=d, the steps are:

a = q_y - r_y

b = r_x = q_x

d = (q+r)/2 dot [a b]

...

It's not clear to me what the dot product is doing here.

##### Share on other sites

a = q_y - r_y looks like a scalar to me (which doesn't make sense for a dot product). Maybe you could post a screenshot of the page you're reading?

Edited by Randy Gaul

##### Share on other sites

Hi Randy,

Attached is an image which preserves the math notation.  Can you explain what the first d equation is doing?

Thanks

##### Share on other sites

Oh now it makes sense, thanks for the image

a and b are scalars that form the vector rq, where rq = q - r, and points from r to q. If we do q + r / 2 we get the midpoint, which is on the bisector. If we dot rq with the midpoint we can solve for d in the equation ax + by = d. You can think of d as the distance of the plane to the origin along the normal [a, b], scaled by the length of [a, b].

Since we know the bisector is perpendicular to rq we can treat rq as the normal of the plane equation [a, b]. To solve for d, we just need to plug in any point on the bisector into the plane equation ax + by = d. x and y are chosen as the midpoint of r and q, since it is easy to calculate this midpoint.

Does this make sense?

Edit:

ax + by = [a, b] dot [x, y] = d

where [x, y] = (q + r) / 2

Edited by Randy Gaul

##### Share on other sites

It does make sense now.  Thanks!

For me to understand what they are doing more fully, I used your statement here

Since we know the bisector is perpendicular to rq we can treat rq as the normal of the plane equation [a, b]. To solve for d, we just need to plug in any point on the bisector into the plane equation ax + by = d. x and y are chosen as the midpoint of r and q, since it is easy to calculate this midpoint.

Expanded the details to the following:

Since we know the bisector is perpendicular to qr we can treat qr as one of the the normals n=[a,b] of the line equation.  To solve for a,b we can calculate the normal as either (-dy,dx) or (dy,-dx) of qr.  In the text they use (-dy,dx) hence

a = -(r_y-q_y) =q_y-r_y  (as stated in text)

b = r_x - q_x (as stated in text)

So now at this point we have a normal and just need to calculate d.  To solve for d, we just need to plug in any point on the bisector into the plane equation ax + by = d. x and y are chosen as the midpoint of r and q, since it is easy to calculate this midpoint.

ie

we have everything we need except d in:

ax + by = d or it's equivalent

p dot n = d

choosing the midpoint for p and [a b] above for n, d becomes:

d=(q+r)/2 dot [q_y-r_y, r_x-q_x]     (as stated in text)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 11
• 15
• 11
• 11
• ### Forum Statistics

• Total Topics
634149
• Total Posts
3015834
×