Results 1 to 20 of 20

Thread: Triangle in Circle Construction without Trig?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    46

    Triangle in Circle Construction without Trig?

    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;


    Y_X_Z
    ---------------------------------------
    97-49-311 = 108 degrees


    Z_Y_X
    ---------------------------------------
    311-97-49 = 48 degrees


    Y_Z_X
    ---------------------------------------
    97-311-49 = 24 degrees


    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.

    Thanks guys!!!


  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Triangle in Circle Construction without Trig?

    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

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Triangle in Circle Construction without Trig?

    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:
    1. x = 49
    2. y = 97
    3. z = 311
    4.  
    5. a1 = y - x
    6. a2 = z - x
    7. a3 = z - y
    8. If a1 > 180 Then a1 = 360 - a1
    9. If a2 > 180 Then a2 = 360 - a2
    10. If a3 > 180 Then a3 = 360 - a3
    11.  
    12. angle1 = (180 - a1) / 2 + (180 - a2) / 2   '107
    13. angle2 = (180 - a2) / 2 + (180 - a3) / 2   '58
    14. 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

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    46

    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?

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Triangle in Circle Construction without Trig?

    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:
    1. x = 49
    2. y = 97
    3. z = 311
    4. rad = 10   ' radius
    5. a1 = y - x
    6. a2 = z - x
    7. a3 = z - y
    8. If a1 > 180 Then a1 = 360 - a1
    9. If a2 > 180 Then a2 = 360 - a2
    10. If a3 > 180 Then a3 = 360 - a3
    11. s1 = Sin(a1 * 3.142 / 360) * rad * 2   'side 1
    12. s2 = Sin(a2 * 3.142 / 360) * rad * 2
    13. s3 = Sin(a3 * 3.142 / 360) * rad * 2
    14.  
    15. angle1 = (180 - a1) / 2 + (180 - a2) / 2
    16. angle2 = (360 - a2 - a3) / 2    ' same calculation as before
    17. 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

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Triangle in Circle Construction without Trig?

    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

    s1 = 5.17703667643103
    s2 = 10.001175884751
    s3 = 5.17703667643103

    angle1 = 135
    angle2 = 135
    angle3 = 150
    Last edited by leinad31; Dec 3rd, 2006 at 07:15 AM.

  7. #7
    Hyperactive Member
    Join Date
    Aug 2006
    Posts
    367

    Re: Triangle in Circle Construction without Trig?

    http://hypertextbook.com/eworld/chords.shtml

    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

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Triangle in Circle Construction without Trig?

    Since he is working with angles, it will definitely involve trigonometry.

  9. #9
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Triangle in Circle Construction without Trig?

    Here try this... uses cosine law

    EDIT: Didn't have time to brute test this earleir... let me know if there are errors.
    Attached Files Attached Files
    Last edited by leinad31; Dec 4th, 2006 at 12:28 AM.

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    46

    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 ????




    Quote 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

  11. #11
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Triangle in Circle Construction without Trig?

    Ok, I've got it working finally. I only tested it for obvious angles that I could see
    (0,90,270) or (0,180,360), etc.
    Attached Files Attached Files

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    46

    ROB123 - Re: Triangle in Circle Construction without Trig?

    Thanks Rob! Will check right away! Will it work with triangles having unequal side lengths? Non-equilaterals? Thats what Im so hoping for!!

    best wishes!



    Quote Originally Posted by Rob123
    Ok, I've got it working finally. I only tested it for obvious angles that I could see
    (0,90,270) or (0,180,360), etc.

  13. #13
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Triangle in Circle Construction without Trig?

    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)

  14. #14
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Triangle in Circle Construction without Trig?

    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:

    AB^2 = Radius^2 + Radius^2 - 2(Radius)(Radius) cos (45 - 10)
    AB^2 = 2(Radius^2) - 2(Radius^2) cos (35)
    AB^2 = 2(Diameter/2)^2 (1 - cos 35)
    AB^2 = (Diameter^2) * (2/4) * (1 - cos35)
    AB^2 = ((Diameter^2)/2 )* (1 - cos35)

    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.

    c^2 = a^2 + b^2 - 2ab*cos (angle@C)

    cos(angle@C) = (a^2 + b^2 - c^2) /2ab
    angle@C = arccos( (a^2 + b^2 - c^2) / 2ab)

    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.

  15. #15

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    46

    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?

    Quote 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)

  16. #16

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    46

    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?

    Quote 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:

    AB^2 = Radius^2 + Radius^2 - 2(Radius)(Radius) cos (45 - 10)
    AB^2 = 2(Radius^2) - 2(Radius^2) cos (35)
    AB^2 = 2(Diameter/2)^2 (1 - cos 35)
    AB^2 = (Diameter^2) * (2/4) * (1 - cos35)
    AB^2 = ((Diameter^2)/2 )* (1 - cos35)

    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.

    c^2 = a^2 + b^2 - 2ab*cos (angle@C)

    cos(angle@C) = (a^2 + b^2 - c^2) /2ab
    angle@C = arccos( (a^2 + b^2 - c^2) / 2ab)

    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.

  17. #17
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: ROB123 - Re: Triangle in Circle Construction without Trig?

    Quote 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

  18. #18
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Triangle in Circle Construction without Trig?

    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.

  19. #19

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    46

    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 !!!






    Quote 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

  20. #20
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Triangle in Circle Construction without Trig?

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width