Drawing Lines

VPulse

Member
Joined
Jan 1, 2005
Messages
5
Programming Experience
3-5
What I am trying to do is drawing a new line starting from a set point at any specified angle. For example the coordinate is (0,0) and I want to draw a line 8 pixels long at a 45 degree angle. The trouble i am having is getting the x2 and y2 coordinate because of the angle. I know there is a simple formula but I can't quite remember it. If anyone knows how to do what I am doing please reply. Thanks.
 
To find the the endpoint of a vector, you would project the endpoint to the x & y axes using sin & cos.
The x component is given by the magnitude of the vector times the Cos of the angle [8*Cos(45 degrees) in your example].
The y component is given by the magnitude of the vector times the Sin of the angle [8*Sin(45 degrees) in your example].

If the angle is always 45 degrees, you know that the x & y components will be equal and the equation simplifies to x2 = y2 = 8*0.7071 = 5.657 [because Sin(45 degrees) = Cos(45 degrees) = 0.7071].

Remember though: traditionally when working with vectors, positive y values are upwards, but with controls, positive y values are downwards.
 
Back
Top