Download

Function for splitting one vector into parallel and perpendicular components to another vector?

Does anyone know a handy way to take vectorA and split it into vectorAper and vectorApar, based on vectorB? vectorApar would represent the portion of vectorA on an axis parallel to vectorB, and vectorAper would be the portion on the plane perpendicular to vectorB.

You mean like this?
17cc679b73531e7a7a74aa066f67ff43b1539350.png

Should work:



/**
 * VectorToSplit = vectorA
 * RefernceVector = vectorB
 * Out_Parallel = vectorApar
 * Out_Perpendicular = vectorAper
 */
void SplitVectorIntoParallelAndPerpendicularComponents(FVector VectorToSplit, FVector ReferenceVector, FVector & Out_Parallel, FVector & Out_Perpendicular)
{
	Out_Parallel = VectorToSplit.ProjectOnTo(ReferenceVector);
	//vectorApar + vectorAper = vectorA
	Out_Perpendicular = VectorToSplit - Out_Parallel;
}

Thanks. I never knew about ProjectOnTo.