# Get the XZ to the right of a rotated point?

I need to do this entirely with math, take a look at this picture: What I'm doing is building a path finder algorithm that basically looks 30 units ahead, raycasts a few times perpendicular to the future point, finds the midpoint between the min/max vectors that found the dirt road, and puts a green cube in the middle.

I thought this would be rather simple, yet here I am trying to figure out how to plot the exact geometry of a rotated left/right projection. I hope I explained this well enough! I'm also open to suggestions on how to do this if my approach is silly. Eventually this path will split and the algorithm has to detect the split and have the user decide which direction to go.

EDIT: After applying the math below (I opted to use the trig version) I go this result on my algorithm. THANK YOU!!! ## 1 Answer

A unit vector in the xz plane pointing at a radianAngle counter-clockwise from the positive x axis has the formula:

Vector3 tiltedRight = new Vector3(
Mathf.Cos(radianAngle),
0,
Mathf.Sin(radianAngle)
);


And a unit vector at the same angle counter-clockwise from the positive z axis has the formula:

Vector3 tiltedForward = new Vector3(
-Mathf.Sin(radianAngle),
0,
Mathf.Cos(radianAngle)
);


So you can compute your points like so:

Vector3 projectedPoint = startPoint
+ titledForward * distanceForward
+   tiltedRight * distanceRight;


Or you can construct a local basis like so and hide all the trig math:

Quaternion turn = Quaternion.Euler(0, degreeAngle, 0);

Vector3 localOffset = new Vector3 (distanceRight, 0, distanceForward);

Vector3 projectedPoint = startPoint + turn * localOffset;

• Thank you this worked brilliantly! I knew there would be some sin/cos involved but wasn't sure how the foward + right worked together. Nice! – mythstified Aug 9 '18 at 3:34
• The Unit Circle to the rescue! :) – DMGregory Aug 9 '18 at 3:44