Hello, I’m trying to calculate the angle offset of two vectors that will create a plane rotated on a pitch-rotation axis.
I’m aware that using the dot product is one way to go about this, but I couldn’t get far after finding my angle, and not knowing how to continue solving to reach my solution.
I did my best to project my problem on this diagram
The pitch angle gets calculated (orange theta) using the world up normal (in green), to the mouse hit direction (in red), and should align to the the surface plane (in purple), and returns the new plane normal.
The new rotated normal should be aligned to the part’s surface normal (in purple) and rotated by the theta angle (in orange) on the pitch axis rotation
The function i'm using to calculate the closest normal to the mouse point:
local function GetSurfaceNormal(cf, point, plane)
local Up = cf.UpVector
local Right = cf.RightVector
local Look = cf.LookVector
local Difference = (point - cf.p)
local plane = plane or Difference.Unit
local upAngle = math.abs(Up:Dot(plane))
local rightAngle = math.abs(Right:Dot(plane))
local lookAngle = math.abs(Look:Dot(plane))
local data = {
{rightAngle, Right, "X"},
{upAngle, Up, "Y"},
{lookAngle, Look, "Z"}
}
table.sort(data, function(next, now)
return next[1] > now[1]
end)
local direction = data[1][2]:Dot(Difference) > 0 and 1 or -1
return direction * data[1][2], direction
end
I’m trying to calculate the pitch rotation of the yellow plane, adjusted to the closest surface normal of a part which should be perfectly aligned in the Yaw and Roll axis of that closest surface normal.
Im still a bit confused what you are trying to achieve, but if I’m understanding correctly you want a cframe that aligns with a surface given you provide it’s normal?
I’d recommend looking at these two posts as they can help you with that.
They aren’t exact duplicates of your problem, but you should be able to distill the information you need from them.