Jump to content
  • Advertisement
Sign in to follow this  
Scythen

How to map a triangle to a circle?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I have an equilateral triangle and its circumcircle is there some way I can map any point in the circle to a point on the triangle? Equilateral triangle with Circumcircle This may not make much sense but what I want to do is make a gauge like the foot gauge in DDR Max but I don’t want the lines. The result would be that any point on the edge of the triangle would map to a point on the circumference of the circle and points inside the triangle would map to points inside the circle. The center of the triangle would map precisely to the center of the circle. Id also like to be able to determine where a point on the circle mapped to the triangle. I hope I explained that well, it’s sounds confusing when I read it [headshake]

Share this post


Link to post
Share on other sites
Advertisement
Yeah, the description is a little confusing but it doesn't sound like an easy thing to describe. :)

I guess the easiest way to figure it out is to ask which shape is your input and which is your output?

Like, do you have a point on a triangle that you want to place on the sphere or vice-versa?

Share this post


Link to post
Share on other sites
Quote:
Original post by Scythen
Id also like to be able to determine where a point on the circle mapped to the triangle.

You could create a linear mapping for that:

You've got 3 points (A,B,C), 3 wedges of the circle (1,2,3) and 3 lines (AB,BC,CA).

A
3 / \ 1
C---B
2

Let's say A is at angle 0º, B is at 120º and C is at 240º.

Find the angle of your arbitrary point, I'll call this O.


assert( O >= 0 && O < 360 )
if( O < 120 ) //point is in wedge 1
{
fr = O/120;
Pt = fr * B + (1-fr) * A;
}
else if( O < 240 )//point is in wedge 2
{
fr = (O-120)/120;
Pt = fr * C + (1-fr) * B;
}
else //( O < 360) //point is in wedge 3
{
fr = (O-240)/120;
Pt = fr * A + (1-fr) * C;
}



Share this post


Link to post
Share on other sites
I'm reading through this in a bit of a rush so I'm not entirely sure on what your desired application is. But you can certainly uniquely map a point on a triangle to a point on a circle (or vice versa).

I'd take a point at the centre of the triangle and map it to the centre of the circle, like you've done in your diagram. Then you need to stretch each ray from the centre to the end of the triangle out to the radius of the circle. I'd probably use a polar coordinate system for the circle, and map the triangle to something similar. You'll need to calculate the length of the line segment from the centre of the triangle to the edge, which you can do given an polar angle by using some trig and the right angle triangles you can contruct using the shortest distance from the centre of the triangle to the edges.

I know that's probably really confusing without a diagram, so I might have to scribble something once I'm at home and have my scanner (and more time).

Share this post


Link to post
Share on other sites
Assuming you want the edge of the triangle to map to the edge of the circle, and points within the triangle to 'blow out' linearly, I think this is quite easy. At the three 'vertex angles' (0, 120, 240 degrees), the mapping is 1:1. At the three 'centre angles' (60, 180, 300 degrees), the mapping is 2:1 (the edge of the triangle is half the distance from the centre that the edge of the circle is). Interpolating linearly between these expansion values (1 and 2) for angles in between (i.e. 45 degrees is 45/60 of the way between 0 and 60, so it has a value (15/60)*1+(45/60)*2 = 1.75) will give you a factor you can use to increase the radius.

Share this post


Link to post
Share on other sites
Thanks for all the replies, even with my poor explanation it seems I got the point across.

Trapper Zoid,
Sounds interesting but I'm not sure I understand it exactly.

Bob Janova, Hodgman,
I think your ideas are closest to what I’m looking for. If I understand your explanation correctly what you’re saying is to find the angle to the point in the triangle that I want to map ‘blow out’ linearly then using that angle find the amount to shift the point outwards. To map the point back to the triangle use the same equation and linearly interpolate the point back toward the center.

PlayfulPuppy,
I have a point on a triangle that needs to be mapped to the circle and I need to go the other way as well.

Thanks everyone!

Share this post


Link to post
Share on other sites
Here's an outline of how I would implement the mapping from a triangle to a circle. (I assume you can work out the reverse from it, but let me know if that's not obvious).



In this diagram, O is the origin (centre of circle and of triangle), and P is the point (x_p, y_p), inside the triangle that you want to map to the circle. The original point within the triangle and the mapped point within the circle should lie on the dotted line.

Firstly, find the gradient of the line OP, which is y_p/x_p.
The equation of the line is therefore y = (y_p/x_p)x.

For each of the three sides of the triangle:
-Calculate the gradient of the line m_s = (y2 - y1)/(x2 - x1) where (x1, y1) and (x2, y2) are the coordinates of the end points of the line (vertices of the triangle). It doesn't matter which point is chosen as which. Its equation is then y-y_1 = m_s(x-x_1).
-Substitute the equation of the line OP into the equation of the line of the triangle side (AB/BC/AC) to find the point of intersection, which should give you:
(y_p/x_p)x-y_1 = m_s(x-x_1)

This can be solved to give:
x = (y1-m_s*x1)/(y_p/x_p-m_s)
y = (y1-m_s*y1)/(1-m_s/y_p)

(You may want to check the maths on that however.)

You should now have three points of intersection. Calculate the distance from the origin [sqrt(x^2 + y^2)] for all of them, and choose the closest point.

Now, the point within the triangle gets mapped to the circle by scaling it by a variable factor. This factor can simply be calculated as r / sqrt(x^2 + y^2), where r is the radius of the circle. Multiply the x and y coordinates of the original point by this factor and you should have your mapped point.

There are probably easier ways to do all this, but hopefully this method will work for you. :)

Share this post


Link to post
Share on other sites
After rethinking this I'm not sure but it looks like alex_myrpg has the only solution that works.

I thought that Bob Janova had it but when I think about the linear interpolation I don’t see how that will result in a curve. Using just points that lay on the edge of the triangle the resulting points will be in straight lines between the corner of the triangle, the center of the edge projected to the circle and the second corner. The factor used to multiply with can’t be linear. Hodgman has the same problem.

Am I wrong?

So, I still haven’t worked it out but I think alex_myrpg is on to it.

[Edited by - Scythen on March 21, 2008 10:46:25 AM]

Share this post


Link to post
Share on other sites
Hmm, you're right, my version will produce a hexagon. However, there is a straight line in the problem: the triangle itself. So try interpolating between 1 and 0.5, and then taking the reciprocal.

Share this post


Link to post
Share on other sites
Bob Janova - I'm not quite sure what method you're getting at, but I'm fairly sure this problem involves finding the distance from a point to a line somewhere. Perhaps I am just missing a simpler way of doing this, however...

Scythen - let me know how well your implementation of my method works. Note that several of the values used in the calculations can be predetermined and stored (e.g. gradients of triangle sides), so the algorithm should not really be that computationally intensive. Still, perhaps you can simplify it a bit further.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!