// Pneumatic Cylinder calculator 

function Pneumatic(f, p, d, dp){
	this.f = f*1; // force (N) 
	this.p = p*1; // pressure (Pa) 
	this.d = d*1; // diameter piston (m)
	this.dp = dp*1; // diameter piston rod (m)
}

// force single acting outstroke
Pneumatic.prototype.forceOutstroke = function(){
	return this.p * Math.PI * Math.pow(this.d/2,2);
}
// required diameter when force and pressure for single acting outstroke cylinder is known
Pneumatic.prototype.reqDiameter = function(){
	return Math.sqrt(this.f * 4 / (this.p * Math.PI));
}
// required pressure when force and diameter for single acting outstroke cylinder is known
Pneumatic.prototype.reqPressure = function(){
	return this.f * 4 / (Math.pow(this.d,2) * Math.PI);
}

// required pressure when force and diameter for a double acting outstroke cylinder is known
Pneumatic.prototype.forceInstroke = function(){
	return this.p * Math.PI * (Math.pow(this.d,2) - Math.pow(this.dp,2)) / 4;
}
// required diameter when force and pressure for double acting outstroke cylinder is known
Pneumatic.prototype.reqDoubleDiameter = function(){
	return Math.sqrt(this.f * 4 / (this.p * Math.PI) + Math.pow(this.dp,2));
}
// required pressure when force and diameter for double acting outstroke cylinder is known
Pneumatic.prototype.reqDoublePressure = function(){
	return this.f * 4 / ((Math.pow(this.d,2) - Math.pow(this.dp,2)) * Math.PI);
}


// returns input values
Pneumatic.prototype.values = function(){
	var msg = this.p + " " 
		+ this.d + " "
		+ this.dp;
	return msg;
}

// Copyright engineeringtoolbox.com