Results 1 to 11 of 11
Like Tree1Thanks
  • 1 Post By jonah

Thread: BASIC Program for Viviani's Theorem on the Equilateral triangle

  1. #1
    Member jonah's Avatar
    Joined
    Apr 2008
    Posts
    223
    Thanks
    27

    BASIC Program for Viviani's Theorem on the Equilateral triangle

    WARNING: Beer soaked rambling/opinion/observation ahead. Read at your own risk. Not to be taken seriously. In no event shall Sir jonah in his inebriated state be liable to anyone for special, collateral, incidental, or consequential damages in connection with or arising out of the use of his beer (and tequila) powered views.

    The subforum description says "For all calculator topics including programming".
    Here it goes:

    Viviani's theorem, named after Vincenzo Viviani, states that the sum of the distances from any interior point to the sides of an equilateral triangle equals the length of the triangle's altitude.

    Came across this beauty a while back from a book and became fascinated with it. Authors suggested to students to check out theorem using good old fashioned ruler. Thought I should supplement that suggestion with a program. Maybe some high school kids can have some fun with it. Just wondering if BASIC is still in use these days though.

    1 REM THIS PROGRAM WILL SHOW THAT THE SUM OF THE PERPENDICULAR DISTANCES
    2 REM FROM AN INTERIOR POINT G OF ANY EQUILATERAL TRIANGLE ABC WITH SIDE
    3 REM LENGTH OF S IS THE SAME NO MATTER WHICH POINT IS CHOSEN. THIS SUM
    4 REM IS = TO THE ALTITUDE OF AN EQUILATERAL TRIANGLE.
    5 REM THE EQUILATERAL TRIANGLE IS POSITIONED ON THE CARTESIAN COORDINATE
    6 REM SYSTEM SO THAT VERTEX A IS AT THE ORIGIN AND SEGMENT AB IS ON THE
    7 REM X-AXIS. VERTEX B IS THEN AT (S,0) AND VERTEX C IS AT
    8 REM [.5*S, .5*SQR(3)*S]. POINT G(X,Y) IS ANY POINT IN THE INTERIOR OF
    9 REM TRIANGLE ABC. IN ADDITION, E(X,0) IS A POINT ON THE X-AXIS SO THAT
    10 REM IT IS BETWEEN THE ORIGIN AND VERTEX B, AND SUCH THAT SEGMENT GE IS
    11 REM PERPENDICULAR TO SEGMENT AB; D IS A POINT ON SEGMENT AC SO THAT
    12 REM IT IS BETWEEN THE ORIGIN AND VERTEX C, AND SUCH THAT SEGMENT GD
    13 REM IS PERPENDICULAR TO SEGMENT AC; F IS A POINT ON SEGMENT CB SO
    14 REM THAT IT IS BETWEEN VERTEX C AND VERTEX B, AND SUCH THAT SEGMENT
    15 REM GF IS PERPENDICULAR TO SEGMENT CB. ACCORDINGLY, THE ALTITUDE OF
    16 REM AN EQUILATERAL TRIANGLE WITH SIDE LENGTH OF S IS GIVEN BY
    17 REM .5 * SQR(3) * S, WHICH IS ALSO THE Y COORDINATE OF VERTEX C.
    30 INPUT "ENTER THE LENGTH S OF EQUILATERAL TRIANGLE ABC WHERE S IS > 0 "; S
    40 IF S > 0 THEN 53
    50 IF S <= 0 THEN 51
    51 PRINT "S MUST BE > 0. TRY AGAIN."
    52 GOTO 30
    53 PRINT "WITH S = "; S; ", X'S DOMAIN (OR INTERIOR X COORDINATE) MUST BE 0 < X < "; S; ""
    60 INPUT "ENTER THE INTERIOR X COORDINATE"; X
    70 IF X > 0 THEN 90
    80 IF X <= 0 THEN 81
    81 PRINT "X MUST BE > 0. TRY AGAIN."
    82 GOTO 60
    90 IF X <= (.5 * S) THEN 110
    100 IF X > (.5 * S) THEN 200
    110 LET A = X * SQR(3)
    120 PRINT "WITH X = "; X; ", Y'S RANGE (OR INTERIOR Y COORDINATE) MUST BE 0 < Y < "; A; ""
    130 INPUT "ENTER THE INTERIOR Y COORDINATE"; Y
    140 IF Y > 0 THEN 160
    150 IF Y <= 0 THEN 151
    151 PRINT "Y MUST BE > 0. TRY AGAIN."
    152 GOTO 130
    160 IF Y < A THEN 390
    170 IF Y >= A THEN 171
    171 PRINT "Y MUST BE < "; A; ". TRY AGAIN."
    172 GOTO 130
    200 IF X < S THEN 220
    210 IF X >= S THEN 211
    211 PRINT "Y MUST BE < "; S; ". TRY AGAIN."
    212 GOTO 60
    220 LET B = (-1) * SQR(3) * X + SQR(3) * S
    230 PRINT "WITH X = "; X; ", Y'S RANGE (OR INTERIOR Y COORDINATE) MUST BE 0 < Y < "; B; ""
    240 INPUT "ENTER THE INTERIOR Y COORDINATE"; Y
    250 IF Y > 0 THEN 270
    260 IF Y <= 0 THEN 261
    261 PRINT "Y MUST BE > 0. TRY AGAIN."
    262 GOTO 240
    270 IF Y < B THEN 390
    280 IF Y >= B THEN 281
    281 PRINT "Y MUST BE < "; B; ". TRY AGAIN."
    282 GOTO 240
    390 LET H = .5 * SQR(3) * S
    400 LET Q = X / 4 + SQR(3) * Y / 4
    410 LET R = (-1) * SQR(3) * Q / 3 + SQR(3) * X / 3 + Y
    420 LET V = 3 * S / 4 + X / 4 - Y * SQR(3) / 4
    430 LET W = SQR(3) * V / 3 - SQR(3) * X / 3 + Y
    440 LET K = SQR((X - Q) ^ 2 + (Y - R) ^ 2)
    450 LET L = SQR((X - V) ^ 2 + (Y - W) ^ 2)
    460 LET Z = Y + K + L
    461 PRINT "WITH POINT G AT ("; X; ","; Y; ")"
    462 PRINT "POINT E IS AT ("; X; ",0), AND"
    463 PRINT "POINT D IS AT ("; Q; ","; R; "), AND"
    464 PRINT "POINT F IS AT ("; V; ","; W; ")"
    465 PRINT "WE THEN HAVE"
    466 PRINT "EG = SQR [ ("; X; " - "; X; ") ^ 2 + ("; Y; " - 0 ) ^ 2 ] = "; Y; ""
    467 PRINT "DG = SQR [ ("; X; " - "; Q; ") ^ 2 + ("; Y; " - "; R; ") ^ 2 ] = "; K; ""
    468 PRINT "FG = SQR [ ("; X; " - "; V; ") ^ 2 + ("; Y; " - "; W; ") ^ 2 ] = "; L; ""
    499 PRINT "THUS,"
    500 PRINT "THE SUM OF PERPENDICULAR DISTANCES FROM AN INTERIOR POINT OF AN EQUILATERAL"
    501 PRINT "TRIANGLE WITH SIDE LENGTH OF "; S; " IS"
    510 PRINT "EG + DG + FG = "; Y; " + "; K; " + "; L; " = " ; Z; ""
    520 PRINT "THE ALTITUDE OF AN EQUILATERAL TRIANGLE WITH SIDE LENGTH OF "; S; " IS"
    521 PRINT ".5 * SQR(3) * "; S; " = "; H; ""
    530 END
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,606
    Thanks
    301

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    Ahhhh.....the language of my heart!

    40 IF S > 0 THEN 53
    50 IF S <= 0 THEN 51
    51 PRINT "S MUST BE > 0. TRY AGAIN."
    52 GOTO 30

    Line 50 not required; the default to line 51 will be automatic.
    (applies to a few other similar 4-line-groups)

    53 PRINT "WITH S = "; S; ", X'S DOMAIN (OR INTERIOR X COORDINATE) MUST BE 0 < X < "; S; ""
    60 INPUT "ENTER THE INTERIOR X COORDINATE"; X
    70 IF X > 0 THEN 90

    Line 70 should be: IF X > 0 AND X < S THEN 90

    There's a few other similar cases.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member jonah's Avatar
    Joined
    Apr 2008
    Posts
    223
    Thanks
    27

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    WARNING: Beer soaked rambling/opinion/observation ahead. Read at your own risk. Not to be taken seriously. In no event shall Sir jonah in his inebriated state be liable to anyone for special, collateral, incidental, or consequential damages in connection with or arising out of the use of his beer (and tequila) powered views.
    To err on the side of plenty is always a good policy but I guess your streamlined or reduced suggestion is better. Ah but nobody on mhf really cares about our language anymore.
    Thanks from DenisB
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,606
    Thanks
    301

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    Quote Originally Posted by jonah View Post
    . Ah but nobody on mhf really cares about our language anymore.
    So true...little do they know about the beauties of the FOR-NEXT excursions,
    the orgasmic stimulations of the IF-THEN-ELSE traffic signals, and, and, and [anything else, Jonah?]

    Think I'll go listen to "Your cheatin' heart" and "There's a tear in my beer" before I get a depression...
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Super Member Rebesques's Avatar
    Joined
    Jul 2005
    From
    My house.
    Posts
    656
    Thanks
    41

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    ...You kids must not have had my ample choice of games on your Amstrads/Commodores/ZX Spectra :P
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,606
    Thanks
    301

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    Quote Originally Posted by Rebesques View Post
    ...You kids must not have had my ample choice of games on your Amstrads/Commodores/ZX Spectra :P
    Commodore?!
    I remember around 1965 writing a Basic program for a Cribbage game (computer against me)
    on a Commodore64: took me some 6 months; every damn card had to be designed;
    time delays had to be through using fake loops....
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Member jonah's Avatar
    Joined
    Apr 2008
    Posts
    223
    Thanks
    27

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    WARNING: Beer soaked rambling/opinion/observation ahead. Read at your own risk. Not to be taken seriously. In no event shall Sir jonah in his inebriated state be liable to anyone for special, collateral, incidental, or consequential damages in connection with or arising out of the use of his beer (and tequila) powered views.

    Oh god how old are you two?!!! (Richard Hammond, Top Gear Episode #18.7)
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,606
    Thanks
    301

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    Quote Originally Posted by jonah View Post
    Oh god how old are you two?!!! (Richard Hammond, Top Gear Episode #18.7)
    My age = 2015 - b where b = my year of birth and 1999 > b > 1900
    Follow Math Help Forum on Facebook and Google+

  9. #9
    MHF Contributor MarkFL's Avatar
    Joined
    Dec 2011
    From
    St. Augustine, FL.
    Posts
    2,005
    Thanks
    745

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    I cut my teeth programming with GW-BASIC supplied with MS-DOS 2.x...interpreted, line-numbered, POKING and PEEKING...it was great fun.
    Follow Math Help Forum on Facebook and Google+

  10. #10
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,606
    Thanks
    301

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    GW-BASIC, yep, that's what I used for my cribbage program.

    Sure used the LOCATE command a lot: placing cards on screen
    and updating the crib board...must have been suffering from
    temporary insanity...program totalled some 800 lines!

    Oh, glad to see you got your red car back Mark!
    Follow Math Help Forum on Facebook and Google+

  11. #11
    Newbie
    Joined
    Oct 2014
    From
    dpham6761
    Posts
    1

    Re: BASIC Program for Viviani's Theorem on the Equilateral triangle

    Really nice. Well done.
    Cheers,
    Resmas
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 10
    Last Post: Nov 21st 2011, 05:49 PM
  2. Equilateral Triangle
    Posted in the Geometry Forum
    Replies: 3
    Last Post: Oct 21st 2010, 04:37 AM
  3. Equilateral Triangle
    Posted in the Geometry Forum
    Replies: 0
    Last Post: Oct 15th 2010, 05:35 PM
  4. ABC Equilateral Triangle
    Posted in the Algebra Forum
    Replies: 1
    Last Post: May 31st 2010, 06:22 PM
  5. Equilateral Triangle
    Posted in the Geometry Forum
    Replies: 2
    Last Post: Nov 20th 2008, 02:13 PM

Search Tags


/mathhelpforum @mathhelpforum