Humm
I have a canvas object. And...
I was wondering myself how to draw a line depending on three points. It's compulsory that it it passes through three points due its a light ray and a prism...
But I only see an action wich is :Draw Line from X1,Y1 to X2,Y2 ...
�Any experience in this?
Use two Draw Line action. One for point A to point B and another from B to C.
Yes, but there is a problem with that: The line must be straight. And the points 1 and 2 are moving all time...
Seems quite difficult...
Develop games in your browser. Powerful, performant & highly capable.
Use X1,Y1 for the actual objects that are moving?
x1 is constant, y1 is variable.
x2 is variable, y2 is constant.
The ray (represented by this line, must go further x2,y2 to the infinite.
Perhaps, this could be useful:
If I want to have an X and Y whatever points in this space, I can use:
((X -x1)/(x2-x1))-((Y-y1)/(y2-y1))
What do you think?
It works! Due to a factor: The final X is always known. The only thing left to find out is the Y. Easy!
You wanted to draw a straight line between 3 points ? How is it possible ? (Unless the points are aligned, but that would be the same as drawing a line between 2 points)
Did you mean 2 points but with only 3 known coordinates ?
I had 2 points known. All are moving al time, like particules in a fluid. The thrird one is a wall. So I know only it's X. The only thing to find out is the Y.
Because of that I must be careful of two moving points to obtain a straight line.
Oh ! And the line will always hit the wall ? Then this should do the trick :
X1 = FirstObject.X
Y1 = FirstObject.Y
X2 = Wall.X
Y2 = FirstObject.Y + Tan(Angle(FirstObject.X, FirstObject.Y, SecondObject.X, SecondObject.Y)) * abs(FirstObject.X - Wall.X)
That was near the solution, thanks! But for some values, the line breaks.
The formula I have finally used and works fine is:
Y=((((X-x1)*(y2-y1))/(x2-x1))+y1
Where x1,x2,y1,y2 and X are known values.
Nevertheless, thanks a lot!
That's pretty much the same formula without using the angle ! <img src="smileys/smiley2.gif" border="0" align="middle" />
Tan(angle) = (y2-y1) / (x2 - x1)
Replacing that in my formula, we obtain the same thing ! Maybe there's something wrong with the angle() function... Nevertheless, you're better off without it !