HELP! Triangle in Circle Construction without Trig?
Hey guys! Am hoping some one might be able to shed some light on what I suspect is a fairly simple code problem
involving geometry.
I'm an intermediate level VB coder, but my math skills are so so.
So;
What I'm trying to do is just this;
Three points on a circle occur at different degrees. These points can be any degree and will vary. I want to find the
ANGLE of degree BETWEEN each point and its neighbour when the three points are viewed as a triangle. For instance;
Three points are generated ;
x = 49 degrees
y = 97 degrees
z = 311 degrees
Lets store the degree points in the above variables; x,y,z
The circle diameter is fixed at 10 units of measure, lets say we are using centimeters.
I want to know what the ANGLE of degree BETWEEN ;
Y_X_Z
Z_Y_X
Y_Z_X
Where the middle variable in the above represents the apex, zenith point of triangle, or the angle between the left and
right degree points
Manually, if I drew this out on paper and used a protractor to measure directly I'd find the degrees to work out as;
BUT how would I CODE this? I want to be able to enter ANY degree value on a circle for any of X,Y,Z.
Also, I'd like to be able to compute automatically the LENGTH of each triangle leg, each of the three lines
making up the triangle.
Importantly, I need to be able to get the angle and line length dimensions for triangles that do not neccessarily
intersect the circle center, radius at all, hence the above example of degrees on a circle of 49, 97 and 311 degrees,
this forms a triangle that does not intersect the circles center.
Can anyone help with some code snippets and hopefully especially any math formulas to derive these sorts of things?
I am familiar with trig functions like AAA, ASA, etc... but this dopes not seem to be what I am looking for since
I am working with a scenario where both triangle angles AND sides are unknowns - all that is known is the three
degree points on the circle that would form the triangle.
I don't have time to do this right now, but this is how I'd start:
Instead of storing the positions as degrees on the circle, create a UDP(User defined type) which stores an x and y co-ordinate.
For example, the degree 0, would be at the very top at the circle. It's X value would be
(Diameter of circle) * cos(0) = 0
Y would be =
(Diameter of circle) * sin(0) = diameter of circle
Now that you have these, you can find the length of a line like this:
sqrt(point1.x + point1.y - point2.x - point2.y)
From there, you can use simple trig to work out the angles
the 3 angles of a equalateral triangle always sum to 180, but any calculation to work them out are really trig
however you can sum the angles of equalateral triangles from the center point of the circle then just add the angles
a triangle from the center from 49 to 97 = 48 degrees angle at the center, so each angle at the circumference is (180 - 48)/2 or 66 degrees
a triangle from the center from 311 to 49 is 180- 311 + 49 or -98 degrees so the angles at the circumference are each 41 degrees ignore the negative
third triangle from 311 to 97 apex angle of returns 17
so the angles of you primary triangle are 83 (66 +17), 58 (41+17) and 107 (66+41)
code like this
VB Code:
x = 49
y = 97
z = 311
a1 = y - x
a2 = z - x
a3 = z - y
If a1 > 180 Then a1 = 360 - a1
If a2 > 180 Then a2 = 360 - a2
If a3 > 180 Then a3 = 360 - a3
angle1 = (180 - a1) / 2 + (180 - a2) / 2 '107
angle2 = (180 - a2) / 2 + (180 - a3) / 2 '58
angle3 = (180 - a3) / 2 + (180 - a1) / 2 '83
Edit: as far as i am aware you would need to use trig (cosine ot the angles of the triangles from the center point), to work out the lengths of the sides
Last edited by westconn1; Dec 3rd, 2006 at 04:35 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
WESTCONN1-Re: Triangle in Circle Construction without Trig?
Thanks for the reply! Only problem is, lets say I am dealing with triangles of unequal lengths, (no equilaterals), and no part of the triangle within the circle actually crosses or touches the circles center.... how do we derive angles of the triangle, formula wise, knowing only the points on the circle from which the triangles lines will be joined?
the above code does that, any 2 points and the circumference of the circle can make a triangle to centerso the 3 points of your triangle can make 3 triangles to the center, so from those (undrawn) triangles you can calculate the angles, and the length of the sides
VB Code:
x = 49
y = 97
z = 311
rad = 10 ' radius
a1 = y - x
a2 = z - x
a3 = z - y
If a1 > 180 Then a1 = 360 - a1
If a2 > 180 Then a2 = 360 - a2
If a3 > 180 Then a3 = 360 - a3
s1 = Sin(a1 * 3.142 / 360) * rad * 2 'side 1
s2 = Sin(a2 * 3.142 / 360) * rad * 2
s3 = Sin(a3 * 3.142 / 360) * rad * 2
angle1 = (180 - a1) / 2 + (180 - a2) / 2
angle2 = (360 - a2 - a3) / 2 ' same calculation as before
angle3 = (180 - a3) / 2 + (180 - a1) / 2
i think the above code will return the right values
if you draw your circle with triangle > then draw from each point to the center you have equalateral triangles, these are the basis for the measurements
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
that works with acute triangles if i am not mistaken (center of circle in triangle), not yet sure though if that approach will work with obtuse triangles (angles are not sums but rather differences).
EDIT: Yup, won't work
x = 0
y = 30
z = 60
rad = 10
a1 = 30
a2 = 60
a3 = 30
Ptolemy worked out some chord tables a while back.. The geometry is daunting, but there are tables at the bottom.. Beyond this (which is using trig tables), anything you do here wil involve trig whether it appears to be trig or not
ROB123 :Re: Triangle in Circle Construction without Trig?
Thanks for your reply, this does seem to work but only for certain values, where diameter = 17 units of measure. What am I missing;
A problem arises in that when I try this code it only seems to work for certain degree entries, for instance I can enter the degrees of
97
49
and it seems to work fine, but if i enter the degrees of ;
x1,x2 = 200
y1,y2= 04
it returns an error
or if i enter
x1,x2 = 20
x1,x2 = 200
the amount it returns is just plain wrong ????
Originally Posted by Rob123
I don't have time to do this right now, but this is how I'd start:
Instead of storing the positions as degrees on the circle, create a UDP(User defined type) which stores an x and y co-ordinate.
For example, the degree 0, would be at the very top at the circle. It's X value would be
(Diameter of circle) * cos(0) = 0
Y would be =
(Diameter of circle) * sin(0) = diameter of circle
Now that you have these, you can find the length of a line like this:
sqrt(point1.x + point1.y - point2.x - point2.y)
From there, you can use simple trig to work out the angles
There's no need to get the cartesian coordinates if your after the angles. You have three angles, all relative to the center of the circle, say they are angleA = 10, angleB = 45 and angleC = 85. From this three angles you can create "pie slices" where the chord is the base/side farthest from the center of the circle and the radius are the other sides of the triangle. Let's look at chord AB, using cosine law:
You can use the same approach for AC^2 and BC^2. Now that you have the chords which are the lengths of the three sides (squared) of the triangle, you can now implement the cosine law again but this time relative to the angles at the points of the triangle rather than the center of the circle.
So you just plug in the values for AB^2, AC^2, BC^2, placing side opposite to angle being derived as c^2.
Translating to cartesian coordinates is just additional coding you don't need to do. And Pythagorean is just a special case of the cosin law (2ab*cos(angle) = 0), so why go through pythagorean when you can get relevant angles directly.
Last edited by leinad31; Dec 4th, 2006 at 12:32 AM.
ROB123 - Re: Triangle in Circle Construction without Trig?
Rob, I do not understand what you mean when you "as long as the triangle
inside the circle doesn't cross lines", ? What does crossing lines mean?
Could you give an example?
Originally Posted by Rob123
It'll work as long as the triangle inside the circle doesn't cross lines, but yes, it works for all triangles ( unless I made a typo with the maths)
LEINAD31 - Re: Triangle in Circle Construction without Trig?
Sounds like a simple and direct approach, however you mention using the
radius and center of the circle. Im hoping to construct triangles that do not neccessarily have any of their sides going through or touching the center, but rather irregular triangles of unequal lengths being constructed anywhere within the circle. If no sides are the radius how can your method still work?
Originally Posted by leinad31
There's no need to get the cartesian coordinates if your after the angles. You have three angles, all relative to the center of the circle, say they are angleA = 10, angleB = 45 and angleC = 85. From this three angles you can create "pie slices" where the chord is the base/side farthest from the center of the circle and the radius are the other sides of the triangle. Let's look at chord AB, using cosine law:
You can use the same approach for AC^2 and BC^2. Now that you have the chords which are the lengths of the three sides (squared) of the triangle, you can now implement the cosine law again but this time relative to the angles at the points of the triangle rather than the center of the circle.
So you just plug in the values for AB^2, AC^2, BC^2, placing side opposite to angle being derived as c^2.
Translating to cartesian coordinates is just additional coding you don't need to do. And Pythagorean is just a special case of the cosin law (2ab*cos(angle) = 0), so why go through pythagorean when you can get relevant angles directly.
Re: ROB123 - Re: Triangle in Circle Construction without Trig?
Originally Posted by astro_girl_690
Rob, I do not understand what you mean when you "as long as the triangle
inside the circle doesn't cross lines", ? What does crossing lines mean?
Could you give an example?
I meant co-ords of 0, 180, 0, where there's two points at one degree.
I fixed that after I wrote the post though, it should give the value of 0 degrees.
I used cartesian co-ords to help test really, so I could plot on the circle to see if the values were correct
Imagine a circle, then draw a line through it... anywhere any angle. The portion of that line within the circle (points included) is called a chord. The longest possible chord is the diamter of the circle (line passes through center also)... and the smallest possible is not a chord anymore but rather a point, the point of tangency to be specific.
Now the distance from an end of the chord to the center of the circle will always be equal to the radius of the circle. That's what I meant about "pie slices"... don't confuse the "pie slices" with your inscribed triangle, that comes later. So you can now get the lengths of the chords based on the radius (or diameter) and the angles relative to the center of the cirlce.
Notice that the chords are also the sides of your inscribed triangle. So you can now implement the cosine law once again.
Re: ROB123 - Re: Triangle in Circle Construction without Trig?
Hi Rob,
I just ran the script you sent. I just LOVE the little graphic you included!
Yayyyy!!!! I can even see the little triangle!
One question, I can figure it out if you are too busy, and I really am very grateful to you for writing this code, very cool!
Wondering, I noticed side lengths are generated in numbers that look like
those 'twp' thingies? I mean, it doesnt seem to be measuring side lengths
in centimeters or anything.
So, if my circle diameter is say 16.5 centimeters, and I want to see the side lengths in similiar units of measure output to say a text box, how can i keep the grpahic image doing its thing but get a representation of the measue in cm? Is there a way to convert the twippies to cms? I dont expect you to solve this for me, but if you might point me in the right direction?
Thanks Rob123 !!!
Originally Posted by Rob123
I meant co-ords of 0, 180, 0, where there's two points at one degree.
I fixed that after I wrote the post though, it should give the value of 0 degrees.
I used cartesian co-ords to help test really, so I could plot on the circle to see if the values were correct
I believe there are 567 twips in a centimeter (or very close to that). Divide the side lengths by that. I'm sure someone knows the exact fraction (it's something like 566.928687457726)