Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculation #6

Open
ALA96 opened this issue May 10, 2018 · 1 comment
Open

calculation #6

ALA96 opened this issue May 10, 2018 · 1 comment

Comments

@ALA96
Copy link

ALA96 commented May 10, 2018

Excuse me Sir, I want to ask about this. What does these lines mean? How to get calculation for pitch and roll?

Thank you for your attention

// Update at 20Hz
var increment = 0;
setInterval(function() {
// Attitude update
attitude.setRoll(30Math.sin(increment/10));
attitude.setPitch(50
Math.sin(increment/20));

// Heading update
heading.setHeading(increment);

// Private methods
function _setRoll(roll){
placeholder.each(function(){
$(this).find('div.instrument.attitude div.roll').css('transform', 'rotate('+roll+'deg)');
});
}

	function _setPitch(pitch){
		// alert(pitch);
		if(pitch>constants.pitch_bound){pitch = constants.pitch_bound;}
		else if(pitch<-constants.pitch_bound){pitch = -constants.pitch_bound;}
		placeholder.each(function(){
			$(this).find('div.instrument.attitude div.roll div.pitch').css('top', pitch*0.7 + '%');
		});
	}

	function _setHeading(heading){
		placeholder.each(function(){
			$(this).find('div.instrument.heading div.heading').css('transform', 'rotate(' + -heading + 'deg)');
		});	
	}
@finnbear
Copy link

finnbear commented Dec 18, 2024

I realize it's been 6 years but, if you store the orientation as a quaternion (e.g. THREE.Quaternion), you can use the following functions to find the pitch and roll:

function pitch(orientation: Quaternion): Number {
    let forward = orientation.multiply(new Vector3(0, 0, -1));
    let forward2d = new Vector2(Math.hypot(forward.x, forward.z), forward.y);
    return Math.atan2(forward2d.y, forward2d.x)
}

function roll(orientation: Quaternion): Number {
    return orientation.toEuler("YXZ")[2];
}

Note: you may have to convert the result from radians to degrees before passing it to this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants