AVS Forum Addicted Member

Join Date: Dec 2006

Posts: 10,733

Mentioned: 12 Post(s)

Tagged: 0 Thread(s)

Quoted: 503 Post(s)

Liked: 345

Math coding is rarely ever short and easy, even the simplest math can sometimes be a MAJOR pain in the rear in code. Some things I can do on a calculator in 10 steps can require 1000 steps in code. Problem is in code things interact and are constantly changing, so the numbers are dynamic and in real-time. Whereas in person, you are just dealing with static numbers in one instance of time.

An IRIS functions on a curve as a response over time, could you theoretically pass data linearly to it in a bunch of conditions and spit out a positional number, yes you can do it that way. As a matter of fact, I'm sure many of the failed IRIS code tried to do it this "easy" way. The problem becomes you're conditions start colliding and the code becomes impossible to debug and tweak, because instead of having a consistent numbering and response system, you just have a conditional mess loosely connected together that starts producing unpredictable results. You add a condition to fix one bug, and that condition affects your other condition, then you end up with an AI problem bordering on Chaos Theory (no thank you) and end up with the butterfly effect.

The proper way is to use curves based on change (calc derivatives) and then modify those with tables of polynomials or variables that correct things to maintain a certain preferred response. Once you have your generic response curves setup, you can then tweak those with additional conditions at the extremes or to handle abnormal response.

**Here is an example of something that would seem to be 10 lines of code, that ends up as 1000...**

This code below does NOTHING else but convert Metric to English and back and forth, nothing else. Should only be 10 lines of code, right?

I wish...

**IRIS code would be much much worse than this.** This isn't even 2% of my math code from the calculator, and my calculator's code isn't as complicated as designing an IRIS would be. This is just a snippet.

//Converts 3.51m to a label like 12 ft 8 in

function convert_M_TO_FTin(meters) {

var meterPos = meters.indexOf(" m");

m = meters.substring(0, meterPos);

var inches = (inPercm * 100) * m;

var ft = Math.floor(inches / 12, 0);

inches = inches % 12;

inches = inches.toFixed(2);

inches = Math.round(inches)

return ft + " ft " + inches + " in";

}

//Converts 3 m 51 cm to a label like 12 ft 8 in

function convert_M_cm_TO_FT_in(meters,cm,round) {

cm = parseFloat(cm);

cm = cm + (meters * 100);

var inches = .393701 * cm;

var ft = Math.floor(inches / 12, 0);

inches = inches % 12;

inches = inches.toFixed(2);

if (round == true) {

inches = Math.round(inches);

inches = inches.toFixed(1);

inches = Math.round(inches);

}

if (inches == 12) {

inches = 0; ft += 1;

}

var ftIn = new Array(ft, inches);

return ftIn;

}

function convert_FT_in_TO_M_cm(FT, inches) {

inches = parseFloat(inches);

inches = inches + (12 * FT);

var cm = inches * cmPerInch;

var m = Math.floor(cm / 100, 0);

cm = cm % 100;

cm = cm.toFixed(1);

cm = Math.round(cm);

var MetersCM = new Array(m, cm);

return MetersCM;

}

//Converts a full label like "12 ft 8 in" to "3.51 m"

function convert_ftin_TO_m(strFtIn) {

var ftPos = strFtIn.indexOf(" ft"); //because we already replaced ft to m

var ft = strFtIn.substring(0, ftPos);

var inches = parseFloat(strFtIn.substring(ftPos + 3, ftPos + 6));

inches = parseFloat(inches) + (parseFloat(ft) * 12);

var meters = ((cmPerInch * inches) / 100).toFixed(2);

return meters;

}

//Changes a label from FT in to M cm

function ChangeLabelTo_M_cm(label) {

label = label.replace(" ft", " m");

label = label.replace(" in", " cm");

return label;

}

function ChangeLabelTo_Ft_in(label) {

label = label.replace(" m", " ft");

label = label.replace(" cm", " in");

return label;

}

function ConvertALL_M_Toftin(ShouldRound) {

var meters; var cm; var ftFloor; var ftIn = new Array(0, 0);

meters = $("tbCeilingHeightFeet").value; cm = $("tbCeilingHeightInches").value;

ftIn = convert_M_cm_TO_FT_in(meters, cm, ShouldRound);

$("tbCeilingHeightFeet").value = ftIn[0]; $("tbCeilingHeightInches").value = ftIn[1];

$("divCeilingHeight").innerHTML = ChangeLabelTo_Ft_in($("divCeilingHeight").innerHTML);

meters = $("tbFeet_FloorToScreen").value; cm = $("tbInches_FloorToScreen").value;

ftIn = convert_M_cm_TO_FT_in(meters, cm, ShouldRound);

$("tbFeet_FloorToScreen").value = ftIn[0]; $("tbInches_FloorToScreen").value = ftIn[1];

$("divScreenToFloor").innerHTML = ChangeLabelTo_Ft_in($("divScreenToFloor").innerHTML);

$("divRightLabel").innerHTML = ChangeLabelTo_Ft_in($("divRightLabel").innerHTML);

$("tbLensDistance").value = (inPercm * $("tbLensDistance").value).toFixed(2);

$("divMount").innerHTML = $("divMount").innerHTML.replace(" cm", " in");

$("tbMountPoleLength").value = (inPercm * $("tbMountPoleLength").value).toFixed(0);

//Convert the Markers

$("divTopMarker").innerHTML = convertMarkers_ToFTin($("divTopMarker").innerHTML);

$("divCenterMarker").innerHTML = convertMarkers_ToFTin($("divCenterMarker").innerHTML);

$("divBottomMarker").innerHTML = convertMarkers_ToFTin($("divBottomMarker").innerHTML);

//Convert txtMinCeilingHeight to Feet/Inches

var txtMeters = $("txtMinCeilingHeight").value;

var txtFtIn = convert_M_TO_FTin(txtMeters);

$("txtMinCeilingHeight").value = txtFtIn;

$("divMountPoleLength").innerHTML = ChangeLabelTo_Ft_in($("divMountPoleLength").innerHTML);

}

function ConvertALL_ftin_To_M() {

var m; var cm; var mFloor; var cmFloor; var MetersCM = new Array(0, 0);

MetersCM = convert_FT_in_TO_M_cm($("tbCeilingHeightFeet").value, $("tbCeilingHeightInches").value);

$("tbCeilingHeightFeet").value = MetersCM[0];

$("tbCeilingHeightInches").value = MetersCM[1];

$("divCeilingHeight").innerHTML = ChangeLabelTo_M_cm($("divCeilingHeight").innerHTML);

MetersCM = convert_FT_in_TO_M_cm($("tbFeet_FloorToScreen").value, $("tbInches_FloorToScreen").value);

$("tbFeet_FloorToScreen").value = MetersCM[0];

$("tbInches_FloorToScreen").value = MetersCM[1];

$("divScreenToFloor").innerHTML = ChangeLabelTo_M_cm($("divScreenToFloor").innerHTML);

$("divRightLabel").innerHTML = ChangeLabelTo_M_cm($("divRightLabel").innerHTML);

$("tbLensDistance").value = (cmPerInch * $("tbLensDistance").value).toFixed(2);

$("divMount").innerHTML = ChangeLabelTo_M_cm($("divMount").innerHTML);

$("tbMountPoleLength").value = (cmPerInch * $("tbMountPoleLength").value).toFixed(0);

$("divMountPoleLength").innerHTML = $("divMountPoleLength").innerHTML.replace(" in", " cm");

//Convert the Markers

$("divTopMarker").innerHTML = convertMarkers_ToMeters($("divTopMarker").innerHTML);

$("divCenterMarker").innerHTML = convertMarkers_ToMeters($("divCenterMarker").innerHTML);

$("divBottomMarker").innerHTML = convertMarkers_ToMeters($("divBottomMarker").innerHTML);

//Parse Ft/in from txtMinCeilingHeight

m = convert_ftin_TO_m($("txtMinCeilingHeight").value);

$("txtMinCeilingHeight").value = m + " m";

//After conversion to meters finishes, we need to correct the Screen Markers and the Req Ceiling Height

forMeters_IfMismatch_CorrectMarkersAndReqHeight();

}

In some cases, yes you could have very simply converted the numbers, but in most cases with math coding there are additional conditions you have to deal with.

Point being, it's never as easy as it sounds...