This might help.
You can substitute angle a
for 90
, sides a
and c
for the sides labelled in the diagram.
This might help.
You can substitute angle a
for 90
, sides a
and c
for the sides labelled in the diagram.
how?
ok this is my code
local primpartpos = CWorkspace.PrimaryPart.Position -- mirror positon
local campos = workspace.CurrentCamera.CFrame.Position
local _,y,_ = CFrame.new(campos,primpartpos):ToOrientation()
Camera.CFrame = CFrame.new(primpartpos)*CFrame.Angles(0,90-y,0)
workspace.Pointer.Orientation = Vector3.new(0,(90-math.deg(y))+45,0) -- this is for angle visualization and +45 to make it accurate as possible.
I got the angle of incidence but uhh nothing else
Then you can do 90 - angleIncidence
to work out theta.
I am doing that 90-y
and y being angle of incidence
Yep - thatāll give you the angle theta you labelled in your original diagram.
So, to make a mirror, you will follow the law of reflection, it has some easy to follow rules.
Hereās a picture to help you understand.
The law of reflection states that the angle of reflection equals the angle of incidence Īør = Īøi . The angles are measured relative to the perpendicular to the surface at the point where the ray strikes the surface.
now if you look, you can create a triangle by each āhalfā from the image (any side of the perpendicular) and from there you can easily get the angles, here for example.
If you were to compare the images, YZ is the normal and the angle and Z is the point where the normal touches the surface of the mirror, the angle we need is c, to get a we need the length of YZ and YX or XZ, you can choose the side thatās easier for you to find and use these formulas.
-- YX
local c = math.atan(YZ / YX)
-- XZ
local a = math.acos(YZ / XZ)
And ya, I think thatās everything. If I missed anything or you need more explanation on a point, feel free to tell me.
Better explanation than I could have come up with, though you may want to edit:
ā¦ for reflection, rather than refraction; a whole different kettle of fish.
I would rather not mention refraction as some might get confused about which one Iām talking about. Thanks tho.
alright that explaination is very good i like it. I understand that the laws of reflections stats that Thetai = ThetaR I got it but the thing is there is always some sort of inversion like its opposite yknow how would I do that? My idea is to make the angle be relative to the surface but how can I do that in Roblox?
The angle ist equel to the arccosine of the dot product of the unit vector from the Hit Position to the camera position and Hit.Normal.
Theta = math.acos((Camera.CFrame.Position - Hit.Position).Unit:Dot(Hit.Normal))
Edit:
You can also directly get the reflection vector.
local d = (Hit.Position - Camera.CFrame.Position).Unit
RefVector = d - 2 * d:Dot(Hit.Normal) * Hit.Normal
for some reason your formula is doing refraction like effect
this one ig is better or maybe not? IDK MATHS OK!
local part = workspace.Part
local port = workspace.port
game:GetService("RunService").Heartbeat:Connect(function()
local startCFrame = part.CFrame -- Where we derive our position & normal
local normal = startCFrame.lookVector
local position = startCFrame.p
local ray = Ray.new(position, normal * 500)
local hit, position, surfaceNormal = game.Workspace:FindPartOnRay(ray)
local reflectedNormal = (normal - (2 * normal:Dot(surfaceNormal) * surfaceNormal))
local Y = math.acos(reflectedNormal.Y)
port.CFrame = CFrame.new(position)*CFrame.Angles(0,Y,0)*CFrame.new(0,0,-10)
end)
code to test
well, you will get the position correct by getting the angle and ending position, by inversion I think you mean the character being inversed so people commonly think of the reflection as being reversed left to right; however, this is a misconception, but Iāll try to help you get as close as possible to it.
You can do calculate starting position and ending position of every part of the playerās character and clone that part and place it there, then destroy it and redo that every frame, make sure to do that client-side so it doesnāt completely break the game from lag.
welp man THANK YOU SO MUCH! AND
how can i forget about you anon! thank you both of you soooo much for the help! I figured it out and now it works!
Try this:
local part = workspace.Part
local port = workspace.port
game:GetService("RunService").Heartbeat:Connect(function()
local startCFrame = part.CFrame -- Where we derive our position & normal
local Direction = startCFrame.lookVector
local position = startCFrame.p
local ray = Ray.new(position, Direction * 500)
local hit, position, surfaceNormal = game.Workspace:FindPartOnRay(ray)
local reflectedNormal = (Direction - (2 * Direction:Dot(surfaceNormal) * surfaceNormal))
port.CFrame = CFrame.lookAt(Vector3.zero, reflectedNormal) + position + reflectedNormal * 10
end)
what does vector3.zero do? is it just Vector3.new(0,0,0
??
Yes. There is also vector3.one wich is just the same as vector3.new(1,1,1)
good for lazy devs like me lol