Forcing a point and line to move in only one direction on canvas

I have a polygon abcd drawn on canvas

Points ( balls ) a,b,c,d,ball1,ball2 are fixed , not moving

ball3 and ball4 are movable points
1

I Want

1- Ball 3 and Ball 4

When I touch one of them, it moves in only one direction, which is the direction of line DC , and does not leave the path of this line

2-

I want the green line connected to the point to move with the point at the same time from the side of the point only

MY TRIAL



AIA FILE
MOVINGLINE(1).aia (5.8 KB)

No trigonometry should be needed for this, as the movable Balls travel in a straight line of constant slope and offset.

Are the two movable Balls allowed to pass each other?

the two movable Balls not allowed to pass each other

I can now move the point and the line together, but I cannot force the movement along the path of the line dc ( Slope ) what shall i do after

blocks(114)
blocks(115)


blocks(119)

MOVINGLINE(2).aia (8.2 KB)


MOVINGLINE1 (1).aia (8.3 KB)
sample run

The trick is to have Y as a function of X for balls on that line.

2 Likes

I will enable the user to draw the polygon. If the user changes the slope of the line to the opposite direction or makes it horizontal, will I need to modify the equations or does it work in all cases?

As long as the line is not vertical it should work

A vertical line would get a divide by zero error.

Try it.

1 Like

done .. thank you
I needed to review some forgotten mathematics laws

The equation of a straight line is y=mx+c m is the gradient and c is the height at which the line crosses the y-axis, also known as the y

The gradient m

is the slope of the line - the amount by which the y-coordinate increases in proportion to the x-coordinate. If you have two points (x1,y1) and (x2,y2) on the line, the gradient is

Screenshot 2024-07-24 195621

If you know one point (x1,y1) on the line as well as its gradient m, the equation of the line is (y−y1)=m(x−x1)

If we are just given two points (x1,y1)

and (x2,y2), we must first work out the gradient using the gradient formula above, and then choose either point to substitute into the straight line equation with this gradient.

I was working away on this quietly, then saw that @ABG had already provided an excellent solution.

Regardless, here is my approach, using the same formula, but with discreet drag events (assumes the four "outer" balls are set at design time):

slantBall.aia (5.5 KB)

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.