I like doing programming but I have a roadblock when it comes to math. As sad as it is, I'm probably the worst at math in my programming class. Don't know why. But for fun I'm making a tree algorithm to generate a branching tree graphic that I will use later. The problem I'm having is with simple trigonometry. Each limb will generate 2 more limbs off of it that is 1/2 the size and pointed in a random direction. All I need to do is generate a random number that is the angle the branch is pointing. But when I record the x/y coordinates the angle does not matter, just the starting and ending x/y coordinates. Here is a graphic I've done to illustrate what I'm trying to find-
Since the angle counterclockwise from A to B is 290 degrees, we can find the angle of BAC by subtracting 270 from it.
Once you have that angle BAC or CBA, you can solve the triangle using the sine/cosine rule. All you need to know is the length AC and BC. Once you have those lengths, you can add them to the co-ordinates of A(800,600) to get the co-ordinates of B.
Sep 24th 2010, 10:05 PM
I can't see your image so I'm not really understanding.
1. Why would subtracting 270 from 290 give us BAC? AC could change without ever affecting the angle of AB.
2. I already know the lengths of AB and AC. It's 30 units. But they do not necessarily form right angles (and do not in the illustration either).
3. Adding 30 to (800, 600) would give me the coordinates of the branch if it were at a perfect 45 degree angle and grew %50 the original size.