Jump to content

math 360 deegres question


Xwad

Recommended Posts

Well it is a difficult problem for me and i can't explain it well. Hope you understand my problem.

I want to rotate a vehicles Z axis to the closer direction of the target Z.

For example: if the vehicles Z is 90˙ and target Z is 180˙ then rotate it in the positive direction (z=z+1) . If the target Z is 20˙ then rotate it in the negativ direction (z=z-1). always in the direction which is closer.

Edited by Xwad
Link to comment
  • Moderators

@Xwad

 

function getRotationOffset (rot1, rot2)
	local rotationOffset = (rot1 - rot2 + 360) % 360;
	if (rotationOffset > 180) then
		rotationOffset = 360 - rotationOffset
	else
		rotationOffset = -rotationOffset
	end
	return rotationOffset
end

function getRotationDifference (rot1, rot2)
	local rotationDifference = (rot1 - rot2 + 360) % 360;
	if (rotationDifference > 180) then
		rotationDifference = 360 - rotationDifference
	end
	return rotationDifference
end

 

Test them out and see which one you think need.

  • getRotationOffset positive and negative.
  • getRotationDifference only positive.

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...