Vector Math Question

Anyone knows how to get rotation of A so that it faces the middle of B and C?

New Bitmap Image (3).jpg

Wish I was better at maths…

Is this really a right angle there or is that just this particular example? I tutor calculus so I might be of some help

Having B and C in 3d space will not give you one determined point A.
A will be surface of sphere of radius 1/2 of BC and with center in middle between B and C.

Better describe what you want to calculate.

Thanks for your time guys. I explained what I need Wrong
I know the Vector3 positions of A, B and C.
I want to get the rotation of A so that it is facing the middle of B and C on all 3 axis

Actually there are formulas for figuring this. Last I checked a Vector3 in Unreal is simply an x,y,z value group. It treats all vectors as having an origin at the center of 3-space and then a displacement is added as needed. All you need to do is treat just one of the vectors above as coming from that origin of (0,0,0) - probably A. I’d treat B as having an origin being displaced to A’s terminus and C’s origin being displaced in the same manner relative to B. That will make the line BC a reference line for determining an angle. Just connect a line from A to BC where angle ABC is 90 degrees. Call this point of intersection P. Then you have to make a decision about which angle you want to consider as the basis of your rotation. PAB or PAC. A is the origin of a sphere where BC is a tangent to that sphere intersecting with the surface at point P. Not having a use case I can’t go any deeper.

You posted while I was still replying. You are trying to trace a vector from A to 1/2 BC then. 1/2 BC is 1/2 (B+C). I’m going to guess that you are trying to determine the path of something going from A to the middle of BC.


I run traces in those 3 points in order to find the distance from landscape. I am trying to find a reliable way to rotate this actor so that when it moves on landscape with elevation, it rotates accordingly. Actor origin point is Trace A

Actually you are trying to keep your actor parallel to the local plane. You need 3 points from the plane, not two, for your problem (lines are defined by two points and planes by three). The point you are looking for is not from point A to BC but from A to BCD. The center point for BCD is (B+C+D)/3
Here’s an article that might give you a sense of what’s going on (you are trying to keep your ship at right angles to the local normal):

Thank you, this is what I am trying to do, I will study the link

I do not know answer out of my head just right now, but to clarify:

You have 3 poinst A,B,C, which define plane in 3d space.
You want to calculate normal vector to that plane.

if so then read this: Cross product - Wikipedia

Then “cross product” from this list:

And if all what you want is cross product then:
Pick one of A,B,C points. I pick A for easy of explaining.
Calculate vectors AB and AC.
Calculate cross product. This will be normal vector to plane.
Now you have UP vector of your spaceship and normal plane (ie cross product which is up vector of landscape surface below ship).
All you need to do is finding rotation from up vector of ship to up vector of landscape (which is cross product)

Hint: for debug create 2 debug traces (and set them to display for one frame). Then trace like 500normal plane and 500up vector of ship. start both at center of ship. Then you have realtime preview of what you are calculating.

New Bitmap Image (4).jpg
Cross product points at the right location, thanks!
But how can I translate this vector to rotation for my pawn?

Rotation along what axis? There are three (which is why it’s called “Three dimensional” :p). Actually what you’ve done here so far is set the current origin point of your actor which is also a pivot point. Add some collision detection so you don’t just go through your ground surface and you can spin along any axis you want.

Vector + Vector (B + C)
Vector / float (Result / 2)

In other words, average B and C by adding them and dividing by two. This will give you the position vector of the point exactly between them.

Find Look At Rotation (A, Result)

Find the look-at rotation from A to the between vector from before.

Finally, I found the solution:
New Bitmap Image (4).jpg
New Bitmap Image (3).jpg

I’m so stealing your code! :stuck_out_tongue: Good job. I have someone on my team who is also cracking his head over vectors. He has to learn things a certain way so I leave him alone, but anything that could also help him I’ll still grab.