Canvas Issue: Drawing a line through 3 points

Get help using Construct 2

Post » Wed Aug 21, 2013 2:54 pm

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?
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Wed Aug 21, 2013 3:00 pm

Use two Draw Line action. One for point A to point B and another from B to C.
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Wed Aug 21, 2013 3:02 pm

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...
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Wed Aug 21, 2013 3:08 pm

Use X1,Y1 for the actual objects that are moving?
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Wed Aug 21, 2013 3:11 pm

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.

B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Wed Aug 21, 2013 3:14 pm

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?
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Wed Aug 21, 2013 3:33 pm

It works! Due to a factor: The final X is always known. The only thing left to find out is the Y. Easy!
B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Wed Aug 21, 2013 3:52 pm

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 ?
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Wed Aug 21, 2013 3:57 pm

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.

B
17
S
4
G
1
Posts: 105
Reputation: 1,874

Post » Wed Aug 21, 2013 4:54 pm

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)
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Next

Return to How do I....?

Who is online

Users browsing this forum: DeXVinogradov, tarek2 and 15 guests