I want you to write a program that outputs a trigonometry circle like the one below. I also want you to animate this circle, having the sine line move along the circumference with the other lines move around it. The minimum number of unique frames is 5. Any lower and your entry will not be counted.

Trig circle

The lines you will need are:

  • Sine (Both)
  • Cosine (Both)
  • Secant
  • Cosecant
  • Tangent
  • Cotangent
  • OA (on diagram)

Edit: No longer a limit

This is a code golf challenge, but I want you to get your code to below my code which is written in BBC BASIC.

Note: I will remove this requirement if the challenge is too hard.

My code: BBC BASIC - 185 bytes, 232 characters (Thanks Steve)

a=0:REPEAT:CLS:a+=0.005:CIRCLE600,500,300:s=300*SIN(a)+500:c=300*COS(a)+600:sc=300*1/COS(a)+600:cs=300*1/SIN(a)+500:MOVE600,500:DRAWc,s:DRAWc,500:DRAW600,500:DRAWsc,500:DRAWc,s:MOVE600,500:DRAW600,cs:DRAWc,s:DRAW600,s:WAIT 1:UNTIL0

Trig Circle

  • 1
    \$\begingroup\$ An image or gif of what your code produces would be very helpful. \$\endgroup\$ – Calvin's Hobbies Aug 19 '14 at 15:56
  • \$\begingroup\$ @Calvin'sHobbies Added \$\endgroup\$ – Beta Decay Aug 19 '14 at 16:00
  • 1
    \$\begingroup\$ I count ASCII 232 characters there, though with tokenisation it probably is 185 bytes. Watch out for that byte counter on BBC Basic for Windows. I usually post as an ASCII count. Your code is probabably golfable down below 185 ASCII characters with VDU's though. \$\endgroup\$ – Level River St Aug 19 '14 at 16:19
  • 1
    \$\begingroup\$ And when the tangent or cotangent are infinite, what should be drawn? Also, what does "output" mean? Can a program write a gif or video file, or should it output in real time on a canvas? \$\endgroup\$ – Peter Taylor Aug 19 '14 at 16:21
  • \$\begingroup\$ @PeterTaylor When tan and cot are infinite, you could draw it to a very long length. Regarding the format of the output, it can be anything. \$\endgroup\$ – Beta Decay Aug 19 '14 at 16:26

Mathematica, 142 bytes


I'm plotting for angles between 0.01 and which conveniently skips any angles where one of the lines would become actually infinite. You can make a GIF from it by replacing Animate with Table, adding a step width of 0.1 say and then using Export on the result:

enter image description here

So I got a bit bored and thought I'd give the full-blown thing a go (with all lines and colours). I omitted the labels, because they are really annoying to position and just clutter everything up.

  c = Cos@t;
  s = Sin@t;
  h = Sign@c;
  v = Sign@s;
  i = .1 h;
  j = .1 v;
    Line /@ {{{c, -s}, {0, 0}, {c, s}}, {{-i, 0}, {-i, j}, {0, 
        j}}, {{-i + c, 0}, {-i + c, j}, {c, j}}, {{c - .1 s, 
        s + .1 c}, {1.1 c - .1 s, 1.1 s + .1 c}, 1.1 {c, s}}},
    Circle[{0, 0}, 0.1, {t, Round[t, Pi]}],
    Line /@ {{{0, 0}, {c, 0}}, {{0, s}, {c, s}}},
    Line /@ {{{0, 0}, {0, s}}, {{c, 0}, {c, s}}},
    Line[{{c, 0}, {h, 0}}],
    Line[{{0, s}, {0, v}}],
    Line[{{h, 0}, {1/c, 0}}],
    Line[{{0, v}, {0, 1/s}}],
    Line[{{0, 1/s}, {c, s}}],
    Line[{{1/c, 0}, {c, s}}],
    Line[{{c, 0}, {c, -s}}],
    Line[{{c, s}, {h, 0}}],
    Line /@ {{{-.45 h, 0}, {-.55 h, 0}}, {{-.45 h, 1/s}, {-.55 h, 
    Arrowheads[{-.05, .05}],
    Arrow[{{-.5 h, 0}, {-.5 h, 1/s}}],
    Line /@ {{{0, -.45 v}, {0, -.55 v}}, {{1/c, -.45 v}, {1/
         c, -.55 v}}},
    Arrow[{{0, -.5 v}, {1/c, -.5 v}}],
    Line[{{c, s}, 1.3 {c, s}}],
    Line /@ {{{0, 0}, {-.5 h, 0}}, {{0, 1/s}, {-.5 h, 1/s}}},
    Line /@ {{{0, 0}, {0, -.5 v}}, {{1/c, 0}, {1/c, -.5 v}}}
    }, PlotRange -> {r = {-2, 2}, r}],
  {t, 0.01, 2 Pi}


enter image description here

And because this is still a code-golf question I golfed this down as well, to see how short I could get it. Currently, 719 bytes:

  • 1
    \$\begingroup\$ Nice, the colours are great! \$\endgroup\$ – Beta Decay Aug 19 '14 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.