How to Generate Vector3 Points around a Local Axis?

Godot Version

4.0

Question

I am generating 6 points around Vector3 B using:

for i in range(6):
	var new_point = Vec3B + Vector3(radius * cos((i*2*PI/6)), 0.0,  radius* sin((i*2*PI/6))))

How can I tilt the axis of these new points so that instead of rotating on the global axis they rotate around a new axis created using Vec3A and Vec3B?

This isn’t optimized

Copy your normalized global vector (a-b). normalized. Rotate it by π/2 then just add it to your b position while rotating it
rotate on your global vector.

var global_axis =  vecA.direction_to(vecB)
var arm = Vector3.UP.cross(global_axis) # get perpendicular vector.

for i in range(6):
	var new_point = vecB+arm.rotated(global_axis, i*TAU/6)
1 Like

Perfect thank you!