Skip to content

Instantly share code, notes, and snippets.

@DaveyJake
Last active February 24, 2023 20:56
Show Gist options
  • Save DaveyJake/d2a210013a265cf63531ee8eb826d1f9 to your computer and use it in GitHub Desktop.
Save DaveyJake/d2a210013a265cf63531ee8eb826d1f9 to your computer and use it in GitHub Desktop.
St. Venant Torsional Constant
/**
* St. Venant torsional constant for structural engineering mathematics.
*
* @remarks Symbol: `J`.
*
* @example Taken from page I-57 the 2013 edition of the AISI Manual for Cold-Formed Steel Design - Vol 1.
* const J = new StVenantTorsionalConstant( 9.000, 2.500, 0.773, 0.059, 0.1875 );
* J.value = 0.00102;
*
* @version 1.0.0
*/
// This class needs on Lodash.js for its private `empty` method.
import _ from 'lodash';
/**
* Begin `StVenantTorsionalConstant` class.
*
* @since 1.0.0
*/
class StVenantTorsionalConstant {
/**
* Total outer height. Symbol: `A'`.
*
* @since 1.0.0
*/
public aPrime: number;
/**
* Total outer width. Symbol: `B'`.
*
* @since 1.0.0
*/
public bPrime: number;
/**
* Total height of lips (if applicable). Symbol: `C'`.
*
* @since 1.0.0
*/
public cPrime: number;
/**
* Shape thickness. Symbol: `t`.
*
* @since 1.0.0
*/
public t: number;
/**
* Half-thickness.
*
* @since 1.0.0
*/
public halfThickness: number;
/**
* Inner-bend radius. Symbol: `R`.
*
* @since 1.0.0
*/
public R: number;
/**
* For section with stiffener lips. Symbol: `α`.
*
* @since 1.0.0
*/
public alpha: number;
/**
* Primary constructor.
*
* @since 1.0.0
*
* @param aPrime
* @param bPrime
* @param cPrime
* @param t
* @param R
*/
constructor( aPrime: number, bPrime: number, cPrime: number, t: number, R: number ) {
this.aPrime = aPrime;
this.bPrime = bPrime;
this.cPrime = cPrime;
this.t = t;
this.halfThickness = t / 2;
this.R = R;
this.alpha = ! this.empty( cPrime ) ? 1.0 : 0.0;
}
/**
* Final value in `in^4` units.
*
* @since 1.0.0
*/
public get value() {
const partOne = Math.pow( this.t, 3 ) / 3,
partTwo = ( this.a + ( this.b * 2 ) + ( this.u * 2 ) + this.alpha * ( ( this.c * 2 ) + ( this.u * 2 ) ) );
return partOne * partTwo;
}
/**
* Inner-bend radius.
*
* @since 1.0.0
*/
public get r() {
return this.R + this.halfThickness;
}
/**
* Parameter `a`.
*
* @since 1.0.0
*/
public get a() {
return this.aPrime - ( 2 * this.r + this.t );
}
/**
* Parameter `b`.
*
* @since 1.0.0
*/
public get b() {
return this.bPrime - ( this.r + this.halfThickness + this.alpha * ( this.r + this.halfThickness ) );
}
/**
* Parameter `c`.
*
* @since 1.0.0
*/
public get c() {
return this.alpha * ( this.cPrime - ( this.r + this.halfThickness ) );
}
/**
* Parameter `u`.
*
* @since 1.0.0
*/
public get u() {
return Math.PI * this.r / 2;
}
/**
* Lodash version of PHP's `empty` function.
*
* @link https://gist.github.com/DaveyJake/2096f3f7b09d26fcce25c1886e2571a0
* @since 1.0.0
* @access private
*
* @param value Value to check.
*
* @returns True if `value` is one of the conditions. False if not.
*/
private empty( value: any | any[] ) : boolean {
/**
* Conditions we want to return as true.
*
* @since 1.0.0
*/
let conditions: Array<boolean> | Array<number> = [
_.isEqual( value, 0 ),
_.isEqual( value, '0' ),
_.isEqual( value, false ),
_.isEqual( value, 'false' ),
_.isEqual( value, '' ),
_.isEqual( value, [] ),
_.isEqual( value, {} ),
_.isEqual( _.isNaN( value ), true ),
_.isEqual( value, 'NaN' ),
_.isEqual( _.isNull( value ), true ),
_.isEqual( value, 'null' ),
_.isEqual( _.isUndefined( value ), true ),
_.isEqual( value, 'undefined' )
];
// Convert boolean conditions to integers: true = 1; false = 0.
conditions = _.map( conditions, _.toNumber );
// Get the sum of the conditions.
const result = _.sum( conditions );
// If the result is greater than 0, we know it's empty.
if ( result > 0 ) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment