Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 making an equilateral triangle using draw.line and pythagorean theorem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hendo




PostPosted: Mon Feb 19, 2007 8:05 pm   Post subject: making an equilateral triangle using draw.line and pythagorean theorem

Hi, I'm new to Turing and I have been trying to find a way to make an equilateral triangle using three draw.line commands and pythagorean theorem, but to no avail... It's in a module file so it will have to be able to be made any size that the user species. TIA!


Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Mon Feb 19, 2007 8:44 pm   Post subject: Re: making an equilateral triangle using draw.line and pythagorean theorem

I already helped you out in the IRC channel, but for the benefit of others:

Posted Image, might have been reduced in size. Click Image to view fullscreen.
Hendo




PostPosted: Mon Feb 19, 2007 9:51 pm   Post subject: Re: making an equilateral triangle using draw.line and pythagorean theorem

ok, i know this isn't turing code but since i'm on my mac and im using TNT Basic, this is what I tried (you'll notice that TNT Basic and Turing are similar)

code:
procedure eq (int x, int y, int size, int col)
int x2, y2, x3, y3, height
height= InvTan (height/(size/2))
x2 = x+size
y2=y
x3=(x+size)/2
y3=x3+height
set pen colour col
Line x, y To x2, y2
set pen colour col
Line x, y To x3, y3
set pen colour col
Line x2, y2 To x3, y3
end proc
while not Mouse Button
set pen colour white
paint canvas
eq(100, 200, 50, red)
draw frame
wend


Unfortunately this created a scalene triangle...i must be doing something wrong....
zylum




PostPosted: Tue Feb 20, 2007 2:11 am   Post subject: Re: making an equilateral triangle using draw.line and pythagorean theorem

you could try this thread for a nice solution: http://compsci.ca/v3/viewtopic.php?t=14543&highlight=triangle&sid=65c9d8edf28bf760b924a23f861c9663

if you *need* to use pythagorean then heres a method you can use:

your initial point is (x, y)
your side length is L so the next point on the base is (x + L, y)
the x coord for the last point is x + L/2
the y coord for the last point is (using pythagorean theorem) sqrt(L^2 - (L/2)^2)

sorry i was too lazy to draw up pictures Embarassed
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: