DotProduct() Implementation

I wanted to see DotProduct() Implementation, but I found only this:

DotProduct

can somebody explain how it equal a * b = ||a|| ||b|| cos(0)?

Hi Levani
Here is a explanation of how they reached there (The proof section, case 1):
https://proofwiki.org/wiki/Cosine_Formula_for_Dot_Product

Thank you for answering Maxim, but as I remember from school there are two case of Vector’s scalar multiplies:

  1. a * b = ||a|| ||b|| cos(0)
  2. a * b = (X1 * X2) + (Y1 * Y2)

and in our case is used first version because we need angle, Is my view point right?

  1. my question is about how this { return A | B } binary operation is equal a * b = ||a|| ||b|| cos(0) ?
    and in general How is it possible to do a binary operation with vector?

These are just two different ways of calculating dot product. I am sure that in unreal implementation
they used second one as it requires less computation.

If you are familiar with operator overloading then the answer is:
They overloaded | operator to be a dot product.

So probably implementation of operator | is something like following:

float operator|(const &FVector other) {
    return (this.X * other.X) + (this.Y * otherY) + (this.Z * other.Z);
}

Update: Here is the actual code implementation by the way (Line 1279):
https://github.com/EpicGames/UnrealEngine/blob/dbced2dd59f9f5dfef1d7786fd67ad2970adf95f/Engine/Source/Runtime/Core/Public/Math/Vector.h

ahhhh I don’t think about this. It’s not binary operation it’s overload operator :slight_smile: now its clear. Thank you Maxim

Privacy & Terms