# help computing positions of points

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

## Recommended Posts

I've been trying to figure out a solution for this math problem. It might be simple, it might be impossible. I don't know because I am still very inexperienced in this domain.

I will be referring to this drawing:

The Problem:
This drawing depicts two rectangles lying on the x-z plane. Think of it like you are looking at them top-down (down the -y axis). The black points (H, I, and J) are given as input. The width of the rectangle is always 4. I need to compute the positions of each green point (A through G).

My Partial Solution:
Computing points D through G is easy:
vec3 forward = normalize(I-J); // direction from J to I
vec3 right = cross(forward, vec3(0,1,0)); // direction from F to G
G = J + (right * 2); // 2 = width/2
F = J - (right * 2);


I can use the same formula to compute D and E.

Where I Need Help:

I don't know how to compute A, B or C!
Any help or advice is greatly appreciated!

##### Share on other sites

Unless you know the rotation of the rectangle containing the point H, I don't think you can solve it.  Or if you had the point opposite of H, the midpoint between D & C, you could solve it, because you could then figure out the rotation from there.

##### Share on other sites

Unless you know the rotation of the rectangle containing the point H, I don't think you can solve it.  Or if you had the point opposite of H, the midpoint between D & C, you could solve it, because you could then figure out the rotation from there.

I thought it might not be possible but I needed another set of eyes to confirm. Thanks for taking the time to respond.

##### Share on other sites
Consider the point K that is the midpoint of DC. HK is a line parallel to BD and AC and perpendicular to DC.

Think of D as being the center of a circle with radius 2. K lies on this circle and is such that HK is a tangent to the circle. Also, lies on the line DC. There's lots of information online about finding tangent lines that pass through a circle and an external point. Pick the tangent line that also intersects the midpoint of DC.

One you find that tangent line, you can trivially find the normal of it along DC. Normalize and scale by 4. That's the location of C. Use this same normal scaled by 2 and -2 relative to H to find A and B.

##### Share on other sites

Consider the point K that is the midpoint of DC. HK is a line parallel to BD and AC and perpendicular to DC.

Think of D as being the center of a circle with radius 2. K lies on this circle and is such that HK is a tangent to the circle. Also, lies on the line DC. There's lots of information online about finding tangent lines that pass through a circle and an external point. Pick the tangent line that also intersects the midpoint of DC.

One you find that tangent line, you can trivially find the normal of it along DC. Normalize and scale by 4. That's the location of C. Use this same normal scaled by 2 and -2 relative to H to find A and B.

I'm not sure I follow, it sounds like you're using DC (which is undefined, as he doesn't have C) to find C.  Am I misinterpreting?

##### Share on other sites

One alternative I can think of:

- Consider D to be a hinge.
- Place a new rect A'B'C'D' and point H' directly adjacent to DEFG and treat this as being a rotated version of ABCD.
- You now know the positions of both H' and H. Calculate the angle formed between them using D as the common vertex.
- Use that angle to rotate points A' through C' about D, back to their expected positions.

You could probably do this entirely with matrices and never actually measure an angle (I suspect), but I'm not good enough with linear algebra to verify that.

[attachment=19859:4vq7.png]

Edited by Nypyren

##### Share on other sites

Consider the point K that is the midpoint of DC. HK is a line parallel to BD and AC and perpendicular to DC.

Think of D as being the center of a circle with radius 2. K lies on this circle and is such that HK is a tangent to the circle. Also, lies on the line DC. There's lots of information online about finding tangent lines that pass through a circle and an external point. Pick the tangent line that also intersects the midpoint of DC.

One you find that tangent line, you can trivially find the normal of it along DC. Normalize and scale by 4. That's the location of C. Use this same normal scaled by 2 and -2 relative to H to find A and B.

I understand exactly what you mean. I thought of D being the center of a circle with radius 2 earlier but I have never worked with tangents before so my thought train ended there. I will try to work out a solution with this tomorrow, it looks like a sound solution. Thanks so much!

##### Share on other sites

One alternative I can think of:

- Consider D to be a hinge.
- Place a new rect A'B'C'D' and point H' directly adjacent to DEFG and treat this as being a rotated version of ABCD.
- You now know the positions of both H' and H. Calculate the angle formed between them using D as the common vertex.
- Use that angle to rotate points A' through C' about D, back to their expected positions.

You could probably do this entirely with matrices and never actually measure an angle (I suspect), but I'm not good enough with linear algebra to verify that.

Not sure I entirely follow. I am going to try to implement SeanMiddleditch's solution tomorrow. Thanks for your response!

##### Share on other sites

Not sure I entirely follow. I am going to try to implement SeanMiddleditch's solution tomorrow. Thanks for your response!

Sorry. I edited my post with a picture. I only have mspaint so apologies for the low quality.

##### Share on other sites
Hmm. I just realized my technique only works if the problem guarantees the two rectangles will also have the same length, which your original post didn't specify. Disregard my technique if the rectangles can be different lengths. Edited by Nypyren

• ### What is your GameDev Story?

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

• 15
• 11
• 9
• 9
• 40
• ### Forum Statistics

• Total Topics
634130
• Total Posts
3015705
×