Angles and getting them

I want to know how to get this angle:

and this angle:

I know dot product can be used for the second one but what about the first.

I have tried using cross but could not get it to work

please help

1 Like

Like this:

2 Likes

Hear ye, hear ye that be the dot product it be.

1 Like

Yep, you can use it to get the angle between any two vectors like you stated. What’s the question then?

See the first image, the dot product won’t work there. Can’t use the same dot product for x and y thats a magnitude

use trig on the opposite and adjacent lengths?

number math.atan ( number x )
Returns the arc tangent of x (in radians).

I don’t see why it couldn’t work

Haven’t said what the dimension the vector going sideways is extending in, so I’d assume it is the part’s LookVector:

local B = Part.LookVector
local hyp = P1 - P2
local ang = math.acos(hyp:Dot(B) / (hyp.Magnitude * B.Magnitude))

You could also use trigonometry with whatever axes you’re using

Do the for pitch and I will be happy as I said before dot product is easy cf.LookVector:Dot(delta) but getting the upppp and downnn angle is hard. I dont work with wedges I work with vectors one is for children and the other is for men so stop talking to me about length

The diagram isn’t meant to depict wedges and even then, there is no difference in visual representation in a 2d diagram – the lines are vectors and the dotted line opposite to the angle between the hypotenuse and adjacent sides of the triangles is not one meant to be considered in this case.

Whatever floats your boat. The definition of a vector is a quantity that has both direction and magnitude (also known as length). No offense, but your sentences really do not make any sense

Anyway, see this:

These two parts form a 45 degree angle with P1 as its vertex. P2 has been positioned such that:

P2.Position = (CFrame.new(P1.Position) * CFrame.Angles(math.rad(45), 0, 0) * CFrame.new(0, 0, -40)).Position

Running this code, which is in the same as the one above:

local P1 = workspace.P1
local P2 = workspace.P2

local hyp = P2.Position - P1.Position
local B = P1.CFrame.LookVector
local ang = math.acos(hyp:Dot(B) / (hyp.Magnitude * B.Magnitude) )

print(math.deg(ang))

Yields an output of 45 degrees. This works for any angle, so the dot product is applicable in this case. It works and I’m confused by what you’re saying. Are they not in line on which ever axis you’re not considering, because if so, then you can project the vectors on the plane you desire to consider, like so (in this case, I want to consider the vectors on the YZ plane):

local hyp = (P2.Position - P1.Position) * Vector3.new(0, 1, 1)
local B = P1.CFrame.LookVector * Vector3.new(0, 1, 1)
local ang = math.acos(hyp:Dot(B) / (hyp.Magnitude * B.Magnitude) )

Are we supposed to be looking at a broader picture? I’m confused and wish you’d elaborate.

2 Likes

Getting that angle should work however the boxes are placed/oriented in space. Can also think of it in terms of (geometry) rays and points instead of LookVectors (though you can still use LookVectors to implement it).

--[[
        p1
        |
        p0 -- p2
]]
local p0 = workspace.p0.Position     -- the point with the angle to be measured
local p1 = workspace.p1.Position     -- a point that lies on the first ray
local p2 = workspace.p2.Position     -- a point that lies on the second ray

local v1 = CFrame.lookAt(p0, p1).LookVector    -- unit vec from p0 -> p1
local v2 = CFrame.lookAt(p0, p2).LookVector    -- unit vec from p0 -> p2

local dot = v1:Dot(v2)   -- get the dot prod 
local theta = math.deg(math.acos(dot))    -- no need to div if using unit vectors

Edit: In that second image, if the line coming out of the top box is the facing/look vector, then you can use that and create another vector pointing to the lower box.

local topBox = topBoxInWorld:GetPivot()
local botBox = lowerBoxInWorld:GetPivot()

local p0 = topBox.Position
local p2 = botBox.Position
local v1 = topBox.LookVector
local v2 = CFrame.lookAt(p0, p2).LookVector 

local dot = v1:Dot(v2) 
local theta = math.deg(math.acos(dot))

-- if theta > 90 then the other box is behind the first

I found it using cross but it will often glicth out and make the part look straight down instead of at the player.

Part1.CFrame.LookVector:Cross((Part2.Position - Part1.Position).Unit)
--math.asin(Cross.X) math.asin(Cross.Y)

but I still dont undersatnd why it will freak ouyt.

When your Cross result == Vector3.new(0,0,0) the .Unit will be “nan, nan, nan”, so maybe that’s what’s happening. It’s smart enough to look down instead of breaking.

Could maybe check for results == Vector3.zero before you get the .Unit and just keep the prev value if the check fails.

This post looks a lot like something I’ve been working on. I’ve been learning trig and made a part with a list of trig functions (including finding angles) that can be performed. Not sure if this will help much, but here it is:

It uses attachments to locate the points and properties of a triangle.

Let me know if this helps at all!