# Triangle Calculations to get all possible permutations

Hello,
I am trying to calculate all possible permutations with a function.
I have 100 numbers for each of the 3 products example

``````>network speed
1.2354
1.2885
1.3569

>network latency
0.263
0.214
0.325

>duration
5.323
6.525
4.784
etc..
``````

if I wanted to get all combinations together I would have to do 100*100*100 = 1,000,000
what would be the best approach for speed and stability ?
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Database and Application DeveloperCommented:
Assuming you have a loop with access to three point for each triangle:

Single aX = 0;
Single aY= 0;
Single bX = 3;
Single bY = 4;
Single cX = 0;
Single cY = 4;

Single base = findBase(aX, aY, bX, bY);
Single height = findBase(aX, aY, bX, bY, cX, cY);

Single area = (base * height)/2.0;
.
.
private single findBase(aX, aY, bX, bY)
{
single b = ((aX-bX)^2 + (aY-bY)^2)^.05;
return b;
}

I will post findBase() function shortly.

Mike
Database and Application DeveloperCommented:
This is the tested solution and it works.
``````        private void button1_Click(object sender, EventArgs e)
{
Single aX = 0;
Single aY= 0;
Single bX = 3;
Single bY = 4;
Single cX = 0;
Single cY = 4;

Single b =findBase(aX, aY, bX, bY);

Single height = findHeight(aX, aY, bX, bY, cX, cY);

Single area = (Single)((b * height) / 2.0);
MessageBox.Show(area.ToString());
}
private Single findBase(Single aX, Single aY, Single bX, Single bY)
{
return (Single)Math.Pow((Math.Pow((aX - bX), 2.0) + Math.Pow((aY - bY), 2.0)), 0.5);
}
private Single findHeight(Single aX, Single aY, Single bX, Single bY, Single cX, Single cY)
{
Single m1 = (Single)(aY - bY) / (Single)(aX - bX);
Single m2 = -(1/m1);
Single hX = (m1*aX- m2*cX + cY - aY)/(m1-m2);
Single hY = m1*hX - m1 * aX + aY;

return (Single)Math.Pow((Math.Pow((cX - hX), 2.0) + Math.Pow((cY - hY), 2.0)), 0.5);
}
``````

Experts Exchange Solution brought to you by