Circle Hell

Discussion in 'Python' started by Talon, Sep 4, 2003.

  1. Talon

    Talon Guest

    Hi all,

    I am new to Tk, so please bear with me. I need someone better at math
    than me to help me figure this out. I am drawing multiple arcs on the
    same circle. All arcs start at 90 and have varying negative extents
    (different colors, goes all the way around. Represents a microbial
    genome). So now that my arcs are drawn, I would would like to draw a
    line, 25 pixels long that starts on the circle at the endpoint of each
    of the arcs, and looks like an extension of the radius extending above
    the circle. Then I would like to print text at the end of this line. So
    my question is how do I dynamically calculate the line coordinates?
    Circle size is fixed, number of arcs and their extents are variable.

    Code for drawing arc;
    $x1,$y1 = 25
    $x2,$y2 = 775
    $xcenter = $x2/2 + $x1;
    $ycenter = $y2/2 + $y1;

    $canvas->createArc($x1,$y1,$x2,$y2,
    -width=>10,
    -outline=>$colors[$color],
    -style=>'arc',
    -start=>90,
    -extent=>-$actual_angle,
    -tags=>$myorfs{$key}[1]);

    What I have so far to draw lines:

    $xstart = (cos($current_arclength)*$radius+$xcenter) /10;
    $ystart = (sin($current_arclength)*$radius+$ycenter) /10;
    $canvas->createLine($xstart+$xcenter,
    $ystart+$ycenter,
    $xstart+($xstart*0.01)+$xcenter,
    $ystart+($ystart*0.01)+$ycenter);

    This draws an oval of lines, inside the orginal circle, with the line
    length having sin periodicity around the circle. Can anyone improve my
    math so that I can get the lines placed properly with the proper length?

    Please email me directly as well as respond to the list. Thanks so much
    in advance.

    --Math Challenged Mark

     
    Talon, Sep 4, 2003
    #1
    1. Advertising

  2. On Thu, 04 Sep 2003 07:55:18 -0700, Talon <> (by way of Talon <>) wrote:

    >Hi all,
    >
    >I am new to Tk, so please bear with me. I need someone better at math
    >than me to help me figure this out. I am drawing multiple arcs on the
    >same circle. All arcs start at 90 and have varying negative extents
    >(different colors, goes all the way around. Represents a microbial
    >genome). So now that my arcs are drawn, I would would like to draw a
    >line, 25 pixels long that starts on the circle at the endpoint of each
    >of the arcs, and looks like an extension of the radius extending above
    >the circle. Then I would like to print text at the end of this line. So
    >my question is how do I dynamically calculate the line coordinates?
    >Circle size is fixed, number of arcs and their extents are variable.
    >
    >Code for drawing arc;
    >$x1,$y1 = 25
    >$x2,$y2 = 775
    >$xcenter = $x2/2 + $x1;
    >$ycenter = $y2/2 + $y1;
    >
    >$canvas->createArc($x1,$y1,$x2,$y2,
    > -width=>10,
    > -outline=>$colors[$color],
    > -style=>'arc',
    > -start=>90,
    > -extent=>-$actual_angle,
    > -tags=>$myorfs{$key}[1]);
    >
    >What I have so far to draw lines:
    >
    >$xstart = (cos($current_arclength)*$radius+$xcenter) /10;
    >$ystart = (sin($current_arclength)*$radius+$ycenter) /10;

    These look ok except dividing by 10, assuming the units for the angle are ok (degrees vs radians?)
    Dividing by 10 seems weird here, so try leaving it out.

    >$canvas->createLine($xstart+$xcenter,
    > $ystart+$ycenter,

    From above, xstart already has xcenter in it, so don't add it again. Same for ycenter.
    > $xstart+($xstart*0.01)+$xcenter,
    > $ystart+($ystart*0.01)+$ycenter);

    If you want to draw a 25-pixel line, where is the "25"? You just need to resolve the 25
    into x and y components and add them to your respective starting points, I would think.
    So UIAM the above becomes (giving a name to the 25-pixel length (assuming dimensions are in pixels)

    $tick_length = 25.0;

    $xstart = cos($current_arclength)*$radius+$xcenter;
    $ystart = sin($current_arclength)*$radius+$ycenter;

    $canvas->createLine($xstart,
    $ystart,
    $xstart+ cos($current_arclength)*$tick_length,
    $ystart+ sin($current_arclength)*$tick_length);

    >
    >This draws an oval of lines, inside the orginal circle, with the line
    >length having sin periodicity around the circle. Can anyone improve my
    >math so that I can get the lines placed properly with the proper length?
    >
    >Please email me directly as well as respond to the list. Thanks so much
    >in advance.
    >
    >--Math Challenged Mark
    >
    >


    HTH

    Regards,
    Bengt Richter
     
    Bengt Richter, Sep 4, 2003
    #2
    1. Advertising

  3. Talon

    Mark Carter Guest

    > $xstart = (cos($current_arclength)*$radius+$xcenter) /10;
    > $ystart = (sin($current_arclength)*$radius+$ycenter) /10;


    I wouldn't be using lengths of arcs, if I were you. And that division
    by 10 looks a bit odd, too.

    Given a circle of radius r, if the arc stops at an angle theta to the
    horizontal (measured anticlockwise from the east), then the point on
    the circle is:
    x = xcentre + r * cos(theta)
    y = ycentre + r * sin(theta)

    If you want to know the point at a distance 25 from the circle, simply
    substitute (r + 25) in the formula above.
     
    Mark Carter, Sep 4, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Talon

    Circle Hell

    Talon, Sep 4, 2003, in forum: Perl
    Replies:
    2
    Views:
    1,103
    Mark Carter
    Sep 4, 2003
  2. =?Utf-8?B?dGFnaHJlZWQ=?=

    moving label in c# around circle

    =?Utf-8?B?dGFnaHJlZWQ=?=, May 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,816
    clintonG
    May 3, 2004
  3. =?Utf-8?B?Rmxhc2ggaW4gU21hcnQgZGV2aWNlIEFwcGxu?=

    Create circle in webform

    =?Utf-8?B?Rmxhc2ggaW4gU21hcnQgZGV2aWNlIEFwcGxu?=, Sep 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,827
    =?Utf-8?B?Rmxhc2ggaW4gU21hcnQgZGV2aWNlIEFwcGxu?=
    Sep 8, 2004
  4. Sphenxes
    Replies:
    2
    Views:
    3,104
    Sphenxes
    Sep 25, 2003
  5. ***C.Steamer***
    Replies:
    4
    Views:
    316
    Sudsy
    Sep 29, 2004
Loading...

Share This Page