I need to be pointed in the right direction. In a program that I'm writing I need to draw an arrow. I have a line that can be any random angle. What formula can I use to draw two other lines that begin at an X2,Y2 point and are slanted at a 45 degree angle for instance. The endpoints of the lines that make up the arrow does not matter.
For example:
X1=0
Y1=0
X2=10
Y2=10
How can I plot an arrow off of theese points using a formula?
OK, when drawing lines it is always a good idea to look at the angle formed between the line and the x-axis.
this way, if you want a line at T degrees, length L from the x-axis starting at X1,Y1, the line is:
(X1,Y1)->(X1+R*cos(T), Y1+R*sin(T))
Then, as you are now wanting two lines 45 degrees off the endpoint, the new lines are at 45+T and 135+T degrees from the X-Axis (or pi/4 +T and 3Pi/4 +T radians)
You can use the same formula then to draw the new lines, with starting point X2=X1+R*cos(T) and Y2=Y1+R*sin(T)
Finally, i'm not too sure about what happens with angles with the same tan value (like, 30 and 210 degrees) whether this works fine, or whether some if-statements must be added to see if the angle is < or >=180 degrees.
alpha is 45 deg. in your case, but I have written the general case.
theta is the angle between the (x1,y1) to (x2,y2) segment and the x axis. In the drawing it is > 180 deg. because the arrow is pointing downwards and to the left.
The coordinates you want to figure out are (x3,y3) and (x4,y4).
I have written a demo project where I have made a few changes to take user scales into account, otherwise if the vertical and horizontal scales are not the same your arrow could come out quite out of this world.
If you did then you could find the position by (this is for X):
(X - Xmin) / (Xmax - Xmin) = decimal percent. of placement inside pic
where Xmin <= X <= Xmax
then
Pic1.left + round( dec. percent * Pic1.Width) = X coordinate
This way, your graph is scalable.
NOTE: Please check to make sure I'm right. Also, sorry if I am reiterating anything here. I did not get a chance to look at the attachment.
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
Originally posted by Darkwraith Couldn't you have an X and Y range?
If you did then you could find the position by (this is for X):
(X - Xmin) / (Xmax - Xmin) = decimal percent. of placement inside pic
where Xmin <= X <= Xmax
then
Pic1.left + round( dec. percent * Pic1.Width) = X coordinate
This way, your graph is scalable.
NOTE: Please check to make sure I'm right. Also, sorry if I am reiterating anything here. I did not get a chance to look at the attachment.
At first glance I'd say this is more or less what I do. See the attachment and take a look at the code.