Current Events > Attn: Coding nerds, help me

Topic List
Page List: 1
clearaflagrantj
11/02/18 11:08:01 AM
#1:


I'm trying to make an equation driven model of a part that has schedule 80 pvc pipe dimensions, so for example if I have a pipe that has a nominal size of 1" the inner diameter = .936" and the outer diameter = 1.315"

Solidworks uses very basic Excel/VB coding language, so I don't care about syntax, I'm just trying to find the best way to make an IF statement or equation that takes the nominal pipe size and spits out the proper ID and OD based on it. The only thing I can think of is a giant nested function, e.g.:

Pipe ID = IF (Nominal = 1, .936, IF (Nominal = 2), 1.913, IF (Nominal = 3), 2.864 ...) etc etc, just a shitload of nested if statements all tied to a bunch of equations with the proper data

Is there a smarter way to do this?
... Copied to Clipboard!
emblem boy
11/02/18 11:09:51 AM
#2:


You can't make like a lookup table? Not sure if that's any easier though
---
Posted with GameRaven 3.5.1
... Copied to Clipboard!
Minute
11/02/18 11:11:37 AM
#3:


Those aren't nested if statements, they're just if statements following one another. Never the most elegant solution but if it works, it works.
---
... Copied to Clipboard!
Unimpressed
11/02/18 11:11:55 AM
#4:


Case statements? Would be less messy than a whole bunch of elseifs. Not sure how to simplify further though. Maybe nested case statements of ranges and individual cases inside?
---
By Whining
... Copied to Clipboard!
clearaflagrantj
11/02/18 11:16:13 AM
#5:


emblem boy posted...
You can't make like a lookup table? Not sure if that's any easier though

I will try this out. Solidworks modeling lets you export/import equation data with either txt files or excel spreadsheets, so if I do it with a spreadsheet I should be able to set it up pretty easy.

Minute posted...
Those aren't nested if statements, they're just if statements following one another. Never the most elegant solution but if it works, it works.

Pretty sure they're nested as an if statement is:

IF (statement, return true, return false)

And in lieu of a false return I just put in a new IF statement.

Unless I am mistaken
... Copied to Clipboard!
Giant_Aspirin
11/02/18 11:16:51 AM
#6:


is there any sort of formula/equation to apply? if not, and the return values are basically 1:1 with the input, the only option you have is a if-else chain (or maybe case-select if thats available)
---
Playing: Dead Cells; Xenoblade 2; Mario Odyssey
(~);} - I suppose it will all make sense when we grow up - {;(~)
... Copied to Clipboard!
Rexdragon125
11/02/18 11:19:41 AM
#7:


I know in VB.NET you go like

Select Case Nominal
Case 1
Return 0.936
Case 2
Return 1.913
Case 3
Return 2.864
End Select

Also you could make an array of doubles and use Nominal as the index of the array, that would make a fast lookup table
... Copied to Clipboard!
Minute
11/02/18 11:47:35 AM
#8:


clearaflagrantj posted...
emblem boy posted...
You can't make like a lookup table? Not sure if that's any easier though

I will try this out. Solidworks modeling lets you export/import equation data with either txt files or excel spreadsheets, so if I do it with a spreadsheet I should be able to set it up pretty easy.

Minute posted...
Those aren't nested if statements, they're just if statements following one another. Never the most elegant solution but if it works, it works.

Pretty sure they're nested as an if statement is:

IF (statement, return true, return false)

And in lieu of a false return I just put in a new IF statement.

Unless I am mistaken

I'm not familiar with the language you're using, but if were C it sounds like it would look like


// Returns the Nominal based on pipe ID using contiguous if statements.
// As an aside, why isn't there a way to tab in gamefaqs coding? Or just some sort of ?
// EDIT: lmao it translated   into a space

float findNominal(int pipeID)
{
if (pipeID == 1)
return .936;
if (pipeID == 2)
return 1.913;
if (pipeID == 3)
return 2.864;
...
return -1.0; // or some other "ERROR" value
}


alternatively, like @Unimpressed said, a case switch.

//Returns the Nominal based on Pipe ID using a case switch.

float findNominalUsingCaseSwitch(int pipeID)
{
switch (pipeID) {
case 1: return .936;
case 2: return 1.913;
case 3: return 2.864;
...
default: return -1; //or some other "ERROR" value
}
}


That would work fine as well. Normally you need 'break's in switches but since you're just returning right away its nbd. If this weren't its own method though, it would look like this:

switch (pipeID) {
case 1: nominal = .936;
break;
case 2: nominal = 1.913;
break;
case 3: nominal = 2.864;
break;
...
default: printf("error") //probably put more info than just 'error' tho
}

---
... Copied to Clipboard!
samurai bandit
11/02/18 11:56:54 AM
#9:


You can just use a dictionary:


Dim dictionary As New Dictionary(Of Integer, Double)
dictionary.Add(1,0.93 )
dictionary.Add(2, 1.39)
....

dictionary.item ("2")

---
Go and watch Ef ~ A tale of memories now!
... Copied to Clipboard!
clearaflagrantj
11/02/18 12:08:11 PM
#10:


Giant_Aspirin posted...
is there any sort of formula/equation to apply? if not, and the return values are basically 1:1 with the input, the only option you have is a if-else chain (or maybe case-select if thats available)

To my knowledge no because pipe ids and ods are based on minimum psi which has no linear/clear relation with the sizes. That's some difficult fluid dynamics calculation
... Copied to Clipboard!
Topic List
Page List: 1