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

Username:   Password: 
 RegisterRegister   
 Triangle Maker
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
uberwalla




PostPosted: Sun Dec 17, 2006 10:42 pm   Post subject: Triangle Maker

ok so i just felt like having something that made equalateral triangles easily. ive made this so far.

code:

var x, y, x2, y2, clr : int
put "Starting X Point: " ..
get x
put "Starting Y Point: " ..
get y
put "Ending X Point: " ..
get x2
put "Ending Y Point: " ..
get y2
put "Color: " ..
get clr
drawline (x, y, x2, y2, clr)
drawline (x, y, x2 - 45, y2 + 90, clr)
drawline (x + 90, y, x2 - 45, y2 + 90, clr)



/*
 drawline (10, 10, 100, 10, clr)
 drawline (10, 10, 55, 100, clr)
 drawline (100, 10, 55, 100, clr)
*/



what i would like some help on is that i got it so that in many arrangements for the coordinates it makes it but a lot it doesn't.

i was wondering if anyone could help me make it so it pretty much always makes one. Right now one that works is when u place 10,10,100,10. as i have made it i tried to take into count the angles to make it and thats why it was like x2- 45 to make that fill up to the 100.

help greatly appreciated. thx.
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Sun Dec 17, 2006 11:05 pm   Post subject: (No subject)

use Draw.Polygon and some trig to get all of the sides equal sizes Very Happy
Piro24




PostPosted: Sun Dec 17, 2006 11:12 pm   Post subject: (No subject)

Well, the way I see it, it's kind of dumb to ask for the ending points, because you are going to be changing them anyways. So just ask for two points (x and y) and then automatically assign the 3rd co-ordinate to a place that would make the first to co-ordinates into an equilateral triangle.
Clayton




PostPosted: Sun Dec 17, 2006 11:25 pm   Post subject: (No subject)

ahh, but then which of the two points left available to make the triangle equilateral do you want?
uberwalla




PostPosted: Sun Dec 17, 2006 11:31 pm   Post subject: (No subject)

i have it set up with the 4 coordinates so that i can not only have it facing up. (meaning pointing to top of screen.) i want it so its at any angle at which the point points too Smile
CodeMonkey2000




PostPosted: Mon Dec 18, 2006 2:14 am   Post subject: (No subject)

you could use pythagoran theorum to find the distance between the first to points, then use that to figure out where your last point should be. i dont know much about trig so i dont know that solution. (Mad i hate bieng in grade 10)
uberwalla




PostPosted: Mon Dec 18, 2006 8:05 am   Post subject: (No subject)

good idea ill try it. and i think you should know some trig. my gr 9 class at school learned a bit.
zylum




PostPosted: Mon Dec 18, 2006 9:00 am   Post subject: (No subject)

the best way i could think of is to inscribe a circle with the triangle. if you think of a circle inscribed with an equalateral triangle, you will notice they both share their centroid. also, from the center of the circle each of the triangles vertices are located at 120 degree increments around the circle (360 / number of sides). knowing all of that you can draw your triangle based on the circles center position and its radius.

here's a more generalized function i had made earlier that you can play around with. it inscribes a circle with a proper polygon with a rotation of angle. with angle at 0 one of the vertices will be at the right side of the circle. angle will rotate the polygon counter-clockwise

code:
proc properPolygon (x, y, numSides, size, angle, c : int)
    var lastX := x + round (size * cosd (angle))
    var lastY := y + round (size * sind (angle))

    for i : 360 div numSides .. 360 by 360 div numSides
        Draw.Line (lastX, lastY, x + round (size * cosd (i + angle)), y + round (size * sind (i + angle)), c)
        lastX := x + round (size * cosd (i + angle))
        lastY := y + round (size * sind (i + angle))
    end for
end properPolygon

properPolygon (maxx div 2, maxy div 2, 3, 50, 10, black)
Draw.Oval (maxx div 2, maxy div 2, 50, 50, grey)
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Mon Dec 18, 2006 8:02 pm   Post subject: (No subject)

we barely did trig. its not enough to do something really cool.
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  [ 9 Posts ]
Jump to:   


Style:  
Search: