0

I have an object that I want to move perpendicular to it.

What am I doing:

  • I determine the middle Point between P1 and P2
  • I define the perpendicular vector

How can I find the point I need depending on the mouse position? (knowing X I have to find Y and vice versa)

enter image description here

DeveloperApps
  • 763
  • 7
  • 16
  • Since you say you already know the perpendicular vector it basically comes down to "How to map the mouse position onto that vector?" => Would this answer your question: [How to find the closest point on a line](https://stackoverflow.com/questions/51905268/how-to-find-closest-point-on-line) – derHugo Mar 11 '22 at 10:02

1 Answers1

0

Let P the middle point, D the perpendicular direction vector, M the mouse point and Q the unknown point. We express that a moving point along D forms a right angle by

(P + t D - M).D = 0

which gives us

t = (M - P).D / D²

and

Q = P + t D