I need to get the angles between each part exactly like this, which is the interior angles rather than exterior angles, but when I try to get the angle between them the 135 degree corner gives me the angle of 45 degrees instead. This is because BOTH 90 degree walls share the same angle, and the wall between them also has the same angle in object space relative to them.
I need to find a way to calculate the interior angles only but i’m not sure how I can do this.
You can loop through an array in which the parts you want to get the angle from are and then you compare the current part’s rotation with the previous one and that let’s you know what the relative angle is.
If you want the absolute angles, then just note down the rotation of what ever axis you want to know it from. Then you know how they are rotated towards the origin.
I am not 100% sure what solution you’re seeking, if you could clarify then I could provide more help.
Maybe you want to know what angle two lines make if you move the pivot which let’s say is a sphere. To calculate the interior angle you need to find out what rotation the lines have and when you do, you add the single coordinate rotations togheter.
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.
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.
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.
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.
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.
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.
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.
What is the actual problem, youre telling me you need interior angles and then telling me you know the interior angles.
I dont know what I am supposed to be fixing, there is nothing to reference.
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
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.