Hi! I’m trying to determine the size of a part for the axis the ray hits it at. So if the ray hits a part’s face that’s on the x axis, it would return the size of the part on the x axis.
I’ve tried a solution so far, but I think my maths might be wrong.
So, currently I’m working on the basis that the point where the ray intersects with the face of the part and the centre point of the part will be at an angle with each other and thus a magnitude of the difference between them will return inaccurate results. So I’ve tried getting the angle between the two vectors:
angle = arccos(vector1 . vector2 / (vector1.Magnitude * vector2.Magnitude))
Then I use this angle to calculate the length of the opposite, with the magnitude of the difference between the two vectors serving as the hypotenuse.
opposite = sin(angle) * hypotenuse
I’m working on the assumption that the length of the opposite here will be half the size of the part for the given axis.
Unfortunately this isn’t working and I’m not sure why. The angle is very small too, I feel like I’ve missed a conversion or something. Hopefully someone with better maths skills can help.
Here’s the full code:
local angle = math.acos(part.Position:Dot(rayResult.Position) / (part.Position.Magnitude * rayResult.Position.Magnitude))
local oppositeLength = math.sin(angle) * (part.Position - rayResult.Position).Magnitude
print(oppositeLength)