Skip to content

Instantly share code, notes, and snippets.

@ptvans
Created November 6, 2013 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptvans/7329718 to your computer and use it in GitHub Desktop.
Save ptvans/7329718 to your computer and use it in GitHub Desktop.
RPM and speed calculator
{"editor_editor":{"coffee":false,"vim":false,"emacs":false,"width":600,"height":300,"hide":false},"description":"RPM and speed calculator","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/UmzNwbl.png","controls":{"rpm":2800,"diam":19.3,"axle":3.25}}
// http://www.crawlpedia.com/rpm_gear_calculator.htm
// RPM = (Axle Ratio x Vehicle Speed x Transmission Ratio x 336.13) / Tire Diameter ]
// = [ (3.73 x 65 x 1.00 x 336.13) / 31 ] = [ 2628 ]
// Note: 336.13 is used to convert the result to RPM =
// [63358 inches per mile / (60 minutes per hour x Pi.)]
// Speed = (RPM * tire diameter) / (Axle Ratio * Transmission Ratio * 336.13)
var rpm = 500;
var diam = 0;
var axle = 3.73;
var convert = 336.13;
var gear = 1;
var ratio = 0;
//transmission gear ratios
var t1 = 3.0;
var t2 = 1.6;
var t3 = 1.0;
var t4 = 0.7;
var t5 = 0.5;
var tratios = [t1, t2, t3, t4, t5];
switch(gear)
{
case 1:
ratio = tratios[0];
break;
case 2:
ratio = tratios[1];
break;
case 3:
ratio = tratios[2];
break;
case 4:
ratio = tratios[3];
break;
case 5:
ratio = tratios[4];
break;
default:
alert("WAT");
}
//controls
trib.rpm = tributary.control({name:"rpm", min: 0, max: 8000});
trib.diam = tributary.control({name:"diam", min: 18, max: 31});
trib.axle = tributary.control({name:"axle", min: 1, max: 4});
var speed = (trib.rpm * diam)/(axle * t1 * convert);
var xscale = d3.scale.linear()
.domain([0, 100])
.range([0, 100])
var svg = d3.select("svg")
.append("svg:g")
var equation = svg.append("g")
.classed("message", true)
.attr("transform", "translate("+ 25 +", "+ 50 +")");
equation.append("text")
.text("speed = (RPM * tire diameter) / (axle ratio * trans ratio * 336)");
equation.append("text")
.text(speed +" = ("+ trib.rpm +" * "+ trib.diam +") / ("+ trib.axle +" * "+ t1 +" * "+ convert +")")
.attr("transform", "translate("+ 0 +", "+ 30 +")");
equation.append("text")
.text("gear: "+gear)
.attr("transform", "translate("+ 0 +", "+ 60 +")");
.message{
font-size: 24px;
fill: grey;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment