Since we were reviewing trig in my math class, I decided I wanted to make a simple program that messes around some trig ratios and to hopefully get me back into some light programming.

The first problem comes with my lack of knowledge on using strings, (and by lack, I mean virtually none). My goal is to have random numbers generated, put into a string, and use those as the vertices of a triangle.

Code:

FnOff
-10->Xmin:-10->Ymin:10->Xmax:10->Ymax
ClrDraw
randIntNoRep(-5,5,6)->L1
toString(L1
"This is where I am stuck"
Line(A,B,C,D
A->G:B->H:C->A:D->B
Line(A,B,E,F


What I don't know how to do is take the numbers out of the string and have them put in the variables "A,B,C,D". After that, I just need to shuffle the numbers around to draw the triangle.

EDIT: Forgot to say this was on Ti 84 plus CE
Why do you need to put them into a string first? You should just be able to use the values from L1 as the triangle corners.
ItsJustSomeDude wrote:
Why do you need to put them into a string first? You should just be able to use the values from L1 as the triangle corners.

Maybe you can, but I don't know how to take numbers out of the list and put them as variables. If I could, that would be much easier.
TI 84, Correct? If so, thenn the syntax is List(Element). So in your case, L1(1) is the first element, L1(2) is the second one, etc.
ItsJustSomeDude wrote:
TI 84, Correct? If so, thenn the syntax is List(Element). So in your case, L1(1) is the first element, L1(2) is the second one, etc.


Is this what you mean?

Code:

FnOff
-10->Xmin:-10->Ymin:10->Xmax:10->Ymax
ClrDraw
randIntNoRep(-5,5,4)->L1
Line(L1(1),L1(2),L1(3),L1(4)
Yes, that should work. Or, you could set your variables to the parts of the list:
L1(1)->A
L1(2)->B
L1(3)->C
L1(4)->D
Well As soon as I figured one thing out, I realized that I had forgotten a different problem. I have successfully made it display randomly generate triangles, but I forgot they need to be right triangles. Does anyone have an idea on how I could modify this code to only generate right triangles?

Code:

FnOff
-10->Xmin:-10->Ymin:10->Xmax:10->Ymax
ClrDraw
randIntNoRep(-9,9,8)->L1
Line(L1(1),L1(2),L1(3),L1(4)
L1(3)->A:L1(4)->B
Line(A,B,L1(5),L1(6)
Line(L1(5),L1(6),L1(1),L1(2)
If a line segment forms a diameter on a circle, then any other point on the circle can be used to create a right triangle with the two endpoints of the line segment.

This means that we can randomly pick any two points A and B and an angle θ from 0 to 359.
Find the midpoint M of the two points, which is the center of the circle
Code:
M = ((xA+xB)/2, (yA+yB)/2)

Next, find the distance between the two points, which is the measure of the diameter of the circle

Code:
d = √((xB-xA)^2+(yB-yA)^2)

We can then use sin and cos to find a point P on that circle, offset from the X axis by θ.

Code:
P = (cos⁻¹(θ)*0.5d, sin⁻¹(θ)*0.5d)
(This is relative to the center of the circle, be sure to add the midpoint you found earlier to that to give absolute coordinates)

Although I haven't tested this, in theory this should always give a third point that forms a right angle to the other two.
Since this is mostly mathematical I'll leave the programming to you.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement