Patryk Janik
Patryk Janik

Reputation: 2623

Find point perpendicular to 2 points

It seems I am bad at vectors and math or forgot my entire university studies...

I have A, B, C points coordinates (X, Y, Z) where Z = 0.

enter image description here

C is placed in a half distance between A, B points.

enter image description here

D, E points are in parallel to A,B line

enter image description here

Any idea how to find D and E positions with three.js?

A, B, C are Vector3 three.js objects.

Any help is appreciated.

Upvotes: 2

Views: 101

Answers (1)

Berthur
Berthur

Reputation: 4495

If C is at half the distance between A and B, offset orthogonally, as your figure seems to indicate, then it is simple:

D = C - 0.5AB and

E = C + 0.5AB,

where AB is the vector from A to B.

In THREE.js, you could write it for example like this:

const abHalf = b.clone().sub(a).multiplyScalar(0.5);
const d = c.clone().sub(abHalf);
const e = c.clone().add(abHalf);

though as usual when working with vectors, there are many other ways to calculate it; you may pick your favourite approach.

Is this what you meant?

Upvotes: 1

Related Questions