How can I find the angles between two parts like in this diagram?

Hello, thank you for your answer. I really appreciate it.

All i’m trying to accomplish here is find the interior angles within a polygon/shape in object space through Roblox. It sounds simple but I have not found a good solution to this problem yet. I know in 2D space how to find the angles, that is easy- but in 3D it becomes a problem because 2 lines share the same rotation (90 degrees), and the line between them has a single rotation as well. That means when doing calculations, the subtraction between the two will always be 45 degrees and NOT 135 degrees because 90 - 45 = 45 and both lines have 90 degree rotation so the same calculation will always be done.

Hope that helped clarify this problem a little bit. Thank you.

1 Like

If this shape is just a polygon where all vectors can be considered co-planar you can use the dot product to find the interior angle between two vectors.

Basically if all the vectors are co-planar, treat it like its 2D.

1 Like

Can you give me an example on how to do that? Thank you very much.

The only issue is I do not know how you are applying this polygon and therefore, I dont know what information you have to derive the definitions of the vectors.

If you are looking for the dot product formula, it is a.b=|a||b|cosθ and you can rearrange to solve for the angle by using cos-1((a.b)/(|a||b|)) = θ

sorry this is really messy through text, but basically its inverse cosine applied to the dot of the vectors divided by their magnitudes multiplied by eachother.

Also to get the scalar value of the dot product normally a.b is just a=(x,y) b=(x,y) where a.b = x^2 + y^2 I think? I just did vectors this year in my calculus course and I can go get a refresher here if thats wrong.

Anyway basically you have to show me what you’re doing for me to know how to define the vectors you need to get these angles.

Thank you for your answer.

The lines represented in the diagram are actually just parts in studio, and I just made the polygon rotating the parts and attaching them in studio. Their orientation values are like 135 degrees, 90 degrees, 0 degrees, etc.

ok so you dont need a general case solution and you already know the angles in the polygon?

I am not completely sure what the problem is anymore, if you already know what the angles should be.

The problem is that because the top side and the bottom side both have the same rotation (90 degrees), and the angled side has the rotation value of lets say 135 degrees, when we do angle calculation, the angle given will always be the same because both top and bottom walls have the same rotation (90 degrees).

However, I want to find the angles that are the interior angles, which is 45 degrees and 135 degrees when we look at the diagram for both 90 degree walls and that angled wall.

So even if I know the angles in object space, I still don’t know what the interior angles are or how to calculate them.

I hoped that helped.

but you are telling me the internal angles are 90, 90, 45, and 135, you already know them.

Are you wondering how to convert them to worldspace from objectspace? Or how to orient those parts in worldspace to get those angles in object space?

No, i’m saying I know how to get interior angles from a polygon in 2D space, but in Studio it is difficult for me to find the interior angles of a 3D polygon because like I said, the top and bottom sides are parallel so they share the same angle in Studio. So when I use that angled wall and either of those parallel walls they will give me the same calculation which is not what I need. I need in this case, 135 degrees and 45 degrees (interior angles) but I don’t know how to get them. Thanks for your help so far and hope this explanation helped clear things up a little.

what are you using to calculate this? Whatever your code is or what you are actually trying to achieve in the game that you are working on.

It wouldn’t matter because the function i’m using to calculate this only takes in the Orientation values of the walls themselves, so because the top and bottom walls (90 degrees) share the same angle, it will always give the same result if we use the angled wall with either of them. Therefore the acute angles in the diagram will be the same while for interior angles, they are different.

That is why I need a new calculation system that takes in account lookVector, etc. instead of just hte orientation themselves.

Thanks.

ok so are you asking for a new script instead of the solution or a fix for your current script?

Also it would be so helpful if you could actually give examples and scripts because this is making no sense anymore.

What part of it doesn’t make sense for you? Maybe I can clarify better? I’m looking for interior angles for a polygon in 3D space.

  1. What is the actual problem, youre telling me you need interior angles and then telling me you know the interior angles.

  2. I dont know what I am supposed to be fixing, there is nothing to reference.

  3. why does the top and bottom being parallel create an issue?

And like I said a polygon in three space if coplanar can be treated relativistically like the vectors are in 2D and therefore you can just apply in the angles in object space in a coplanar context

  1. Vertex A (45deg)
  2. Vertex B (90deg)
  3. Vertex C (90deg)
  4. Vertex D (135deg)

Calculate the distance from Vertex C to Vertex B and to Vertex D. These distances will be our variables for calculating any other angle.

We got:

  1. Distance C to B = disCB
  2. Distance C to D = disCD

!!!disCB + disCD = 90deg!!!
Because we know vertex C is 90deg, the distances CB and CD both summed will equal to the imaginary sum: “90deg”.

(disAB + disAD) / (disCB + disCD) = 0.5 → 90 * 0.5 = 45deg

nvm forget it, it only works if we have the perfect polygon for this calculation

Can you show us your script?

1 Like

I thought I was onto something but I am just dumb (creative)

Hmm, this is not as dumb as I thought. But what could maybe be useful is to use raycasting to get the direction of the distances, because we’ll need the directions to calculate the angles. I am going to sleep now but I can try to figure it out tomorrow if I don’t forget

So are you using part.Orientation.Y in calculating the angles? Does this work?

local function getInteriorAngles(parts: {BasePart}): {number}
	local angles: {number} = table.create(#parts)
	for i: number, part: BasePart in parts do
		local angle1: number = part.Orientation.Y
		local angle2: number = parts[i % #parts + 1].Orientation.Y
		if angle2 < angle1 then
			angle2 += 360
		end
		angles[i] = 180 - (angle2 - angle1)
	end
	return angles
end

This code assumes that the parts are ordered counterclockwise.

I think I found the solution in this thread: Best way to get the angle between two vectors? - #10 by coolalex1835

I used the code given in the thread and so far it works properly, although I might have to do more testing later on. I will also try your solution although i’m not sure how I would write the function that calls the code, i’m not used to that formatting unfortunately.

Thanks everyone for your help.

I found something interesting: Vector3.new():Angle(arg1)

Arg1 takes in another Vector3 value with which the machine returns the angle in radians between it and the Vector3 that you’re running “:Angle” on.

There’s also a second argument but that just makes the inbuilt function return the sign of the angle. Arg2 requires an axis (Not important).