Finding difference between two orientation vectors, in degrees

Hello! I’m trying to make a tree growing system similar to Lumber Tycoon 2’s. To encourage variation in the trees, I’m trying to make the minimum degrees between two branches 20 degrees. I’ve done a good bit of googling but haven’t found any solutions which have worked. I’m terrible at explaining things, so I’ll try to explain in pictures below:


This tree looks pretty good and is what I am aiming for. There’s enough distance between the base of each branch.


This one is pretty bunched up and doesn’t look that great.


And then this one is absolutely terrible.

This is the code to find the degrees between the two Vector3s. These are esentially the orientation of the branch:

function angleBetweenVectors(u: Vector3, v: Vector3)
	return math.deg(math.acos((u:Dot(v) / u.Magnitude) * v.Magnitude));
end

I really am not sure if this is a coding question or a logic question or something else entirely, but this is what I’ve been spending the past two days trying to fix. If you have any ideas please let me know, they’re greatly appreciated.

It should be divided by both |u| and |v|. not divided by one and multiplied by each other. I assume you just had brackets in the wrong place though?
image

function angleBetweenVectors(u: Vector3, v: Vector3)
	return math.deg(math.acos((u:Dot(v) / u.Magnitude) / v.Magnitude));
end

or you could have

function angleBetweenVectors(u: Vector3, v: Vector3)
	return math.deg(math.acos((u:Dot(v) / (u.Magnitude * v.Magnitude)));
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.