Monks-

How can I create an arc (-style=>'chord') with an arrow on the end, in a Perl-Tk canvas?

This sounded like a simple thing for me to answer. It's turning into a quagmire. Here's where I've been so far:

  • Arrow option on $can->createArc()? Nope - arrow option on line items only.
  • Make an arc out of a bunch of lines (needed to ask in CB for math formula).
  • Duh, CB suggestion to put a small line on end of arc, with arrow! Good thinking..., but wait - I can't figure out how to do this, since there's no way I know of to get the coords of the end of the arc to attach a line to (you only get coords of a rectangle that encloses the arc). Back to bunch-o-lines strategy.
  • Built bunch-o-lines prototype (see attached), but arrowhead doesn't follow curve, and there's no way to rotate the arrowhead.
  • Thinking I could create a really short line right at the end, that orients the arrow in the correct direction. Started thinking there has to be a better way. Decided to ask for Monk's help.

    Any thoughts are much appreciated.

    Thanks

    -Craig

    use strict; use warnings; use Tk; my $top = MainWindow->new; my $can = $top->Canvas()->pack(); my @offset = (100, 100); my $PI = atan2(1,1) * 4; my $max = 100; my $radius = 20; my @coords; foreach my $i (1..$max-30) { push(@coords, _circleCoord($i*2*$PI/$max, $radius)); } $can->createLine(@coords, -arrow=>'last', #-arrowshape=>[10, 15, 9], # Goofy arrowhead - this helps tags=>['SELFARROW']); $can->move('SELFARROW', @offset); MainLoop; sub _circleCoord { my $radians = shift || die "Missing radians"; my $radius = shift || die "Missing radius"; my @coords; push(@coords, ($radius * sin($radians))); push(@coords, ($radius * cos($radians))); return(@coords); }

    In reply to Tk:Canvas - Arc with an arrow? by cmv

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.