How do I find angles in a triangle?

What information do you have to start with?

In your picture, you can just use the Size of the parts. Do you not have access to the Size? Do you only have the three vertices? What?

I want it so when the player is looking at the sun it creates a blur effect and when the player is not looking at the sun it destroys it

while wait(.36) do
	local SunDirection = game:GetService("Lighting"):GetSunDirection()
	local CurrentCameraDirection = workspace.CurrentCamera.CFrame.LookVector
	local Math = math.deg(math.atan(SunDirection.X / CurrentCameraDirection.X))
	if Math > 40 and Math < 50 then
		print("Looking at the sun")
	end
end

but the angle is effected by how much you zoom in and out

You use the length of each side which is how long each part is to figure out the angles. You also ensure that you rotated a leg relative to the other leg 90 degrees to make sure it really is a right triangle. The rest is all trigonometry lol. I recommend learning that online in practice math problems.

-Btw you can’t use those formulas because all your parts are collided towards one another, so you can’t get an accurate measurement.

If the “opposite” and “adjacent” side are the same size then it will always read 45 degrees for the two angles?

Your triangle’s legs look pretty equal to me
image

You shoulda started with that :slight_smile:

It’s much easier that this.

local angleBetweenTwoDirections = math.acos(cameraDirection:Dot(sunDirection))

if angleBetweenTwoDirections < math.rad(10) then
    print(“The two directions are close to lined up”)
end

Google “dot product” for more info.

wait i may be worng.
but i think that would’nt work
u should be taking orientation for angles instead of position

I am looking at this but cant make much sense of it Basic Trigonometry

Stop trying to make triangles. You can calculate the angle between any two unit vectors like I showed you, using math.acos and Dot.

idk if am right.
but i think taking orientation would be a better alternative.
so its as simple as this.
(i kind of forgot how to use the lua block sorry.)

local part1 = game.Workspace.part1
local part2 = game.Workspace.part2

local angle = (part1.Orientation - part2.Orientation).X – u can use any values x or y or z.
print(angle)

– this provides the angle between two parts

Yes but I dont know when to use acos asin atan I am having trouble identifying

Like I showed you :slight_smile:

Just to repeat myself:

local angle = math.acos(direction1.Unit:Dot(direction2.Unit))

It will be in radians. Convert it to degrees with local angleInDegrees = math.deg(angle) If you really want.

don’t confuse yourself with complicated functions its just simple orientation calculation.
so if u want to find the angle between partA and partB
(forgive me but i forgot how to use codeblocks sorry!)

(just a single line of code)

local angle = (game.workspace.partA.Orientation - game.workspace.partB.Orientation).X
–x is the axis u want to calculate the angle of.

– it is actually that simple u don’t even need trignometry lol.

This only works if the orientations are aligned on the XZ plane, and if you have Parts to work with. Read OPs post earlier about what they’re actually trying to do (sun flare stuff).

Yeah it works with only parts.
But isn’t that what he asked?

Yeah it works with only parts.
But isn’t that what he asked?
Also it will work on any plane but u may get negative values.

It’s what they asked, but not what they meant. A case of the xy problem. They clarified later in the thread:

I don’t get the last part of your question.
Angle depends on the zoom?
What angle?
Do u mean the amount of blur?

The angle is effected by how much you zoom in and out so if you are not facing the sun and zoom out it will add the blur anyway (which is bad)

Treat each side as a vector then use the law of cosines
To get the vector you need to get the vertices of 1 edge then you got to get the difference of them.
EX: local vector = (E.Position - C.Position)

local hypotenuse = hypotenuse
local opposite = opposite
local adjacent = adjacent

local oppositeTheta = math.deg(math.acos(opposite.Unit:Dot(hypotenuse) / (hypotenuse.Magnitude * opposite.Magnitude)))
local adjacentTheta = math.deg(math.acos(adjacent.Unit:Dot(hypotenuse) / (hypotenuse.Magnitude * adjacent.Magnitude)))
local hypotenuseTheta = 180 - (oppositeTheta + adjacentTheta) --All triangles in the known universe add up to 180 degrees

Ok am not sure it works but try this.
(Let’s hope my maths textbook is true lol)
While true do
Wait(0.016)
Local pos = Workspace.CurrentCamera.CFrame.Position
Local X = pos.X
Local Y = pos.Y
Local Z = pos.Z

Local aX = math.deg(atan(y/x))
Local aZ = math.deg(atan(z/x))

– we won’t be needing angle y since it’s the rotation which is not required.

Now we have them.
Let’s go to the next part.

Local CFtfs = CFrame.new() * CFrame.angles(math.rad(aX),0,math.rad(aZ))

Local camcf = Workspace.currentcamera.CFrame - Workspace.CurrentCamera.CFrame.Position

If CFtfs == camcf then
– make a new blur effect here
End

End)