using System.Collections.Generic;
x = new double[a.x.Length];
for (int i = 0; i < x.Length; i++)
public Vector cross(Vector a)
Vector v = new Vector(3);
v.x[0] = x[1] * a.x[2] - x[2] * a.x[1];
v.x[1] = x[2] * a.x[0] - x[0] * a.x[2];
v.x[2] = x[0] * a.x[1] - x[1] * a.x[0];
public Vector plus(Vector a)
Vector v = new Vector(x.Length);
for (int i = 0; i < x.Length; i++)
public Vector diff(Vector a)
Vector v = new Vector(x.Length);
for (int i = 0; i < x.Length; i++)
public double dot(Vector a)
for (int i = 0; i < x.Length; i++)
public void scale(double a)
for (int i = 0; i < x.Length; i++)
for (int i = 0; i < a; i++)
public Matrix(int a, int b)
for (int i = 0; i < a; i++)
public Vector mult(Vector a)
Vector b = new Vector(a.x.Length);
for (int i = 0; i < a.x.Length; i++)
public double mult(Vector a, int i)
for (int j = 0; j < a.x.Length; j++)
public string record = "Hello World!";
public void read(string name)
StreamReader sr = new StreamReader(name);
public void open(string name)
sw = new StreamWriter(name);
public void write(string text)
public Vector pos = new Vector(3);
public Vector disp = new Vector(3);
public Matrix dir = new Matrix(3);
public string ObjFormat()
string obj = "v " + vertex[0].x[0] + " " + vertex[0].x[2] + " " + -vertex[0].x[1];
for (int i = 1; i < vertex.Length; i++)
obj += "\nv " + vertex[i].x[0] + " " + vertex[i].x[2] + " " + -vertex[i].x[1];
if (type == "1D" || type == "Pier")
obj += "\nf -1 -2 -4 -3";
obj += "\nf -5 -6 -8 -7";
obj += "\nf -3 -4 -8 -7";
obj += "\nf -1 -2 -6 -5";
obj += "\nf -1 -3 -7 -5";
obj += "\nf -2 -4 -8 -6";
else if (type == "2D" || type == "2dS" || type == "3D")
obj += "\nf -2 -3 -6 -5";
obj += "\nf -1 -2 -5 -4";
obj += "\nf -1 -3 -6 -4";
public void makeVtx(double scale)
D = Math.Max(Math.Sqrt((k[1] / k[0]) * 12), 0.1);
B = Math.Max(Math.Sqrt((k[2] / k[0]) * 12), 0.1);
for (int x = 0; x < 2; x++)
for (int y = 0; y < 2; y++)
for (int z = 0; z < 2; z++)
int i = 4 * x + 2 * y + z;
vertex[i] = new Vector(n[x].disp);
vertex[i] = vertex[i].plus(n[x].pos);
Vector dirY = new Vector(dir.v[1]);
dirY.scale((y - 0.5) * B);
vertex[i] = vertex[i].plus(dirY);
Vector dirZ = new Vector(dir.v[2]);
dirZ.scale((z - 0.5) * D);
vertex[i] = vertex[i].plus(dirZ);
else if (type == "2D" || type == "2dS")
for (int z = 0; z < 2; z++)
for (int a = 0; a < 3; a++)
vertex[i] = new Vector(n[a].disp);
vertex[i] = vertex[i].plus(n[a].pos);
Vector dirZ = new Vector(dir.v[2]);
dirZ.scale((z - 0.5) * k[2]);
vertex[i] = vertex[i].plus(dirZ);
for (int z = 0; z < 2; z++)
for (int a = 0; a < 4; a++)
vertex[i] = new Vector(n[a].disp);
vertex[i] = vertex[i].plus(n[a].pos);
Vector dirZ = new Vector(dir.v[2]);
dirZ.scale((z - 0.5) * 0.2);
vertex[i] = vertex[i].plus(dirZ);
for (int i = 0; i < 6; i++)
vertex[i] = new Vector(n[i].disp);
vertex[i] = vertex[i].plus(n[i].pos);
dir.v[0] = n[1].pos.diff(n[0].pos);
dir.v[1] = dir.v[2].cross(dir.v[0]);
dir.v[2] = dir.v[0].cross(dir.v[1]);
Vector v1 = n[1].pos.diff(n[0].pos);
Vector v2 = n[2].pos.diff(n[0].pos);
Vector v3 = v1.cross(v2);
void findNode(ref Node a, string words)
for (int k = 0; k < N.Length; k++)
public void readModel(string record)
string[] lines = record.Split('\n');
List<Node> NL = new List<Node>();
for (int i = 0; i < lines.Length; i++)
string[] words = lines[i].Split('\t', ' ', ',', ';');
if (words.Length > 4 && !words[0].Contains('#'))
for (int j = 1; j < 4; j++)
a.pos.x[j - 1] = double.Parse(words[j]);
List<Element> EL = new List<Element>();
for (int i = loc + 1; i < lines.Length; i++)
string[] words = lines[i].Split('\t', ' ', ',', ';');
if (words.Length > 7 && !words[0].Contains('#'))
Element a = new Element();
if (words[1] == "1D" || words[1] == "1d")
for (int j = 2; j < 4; j++)
findNode(ref a.n[j - 2], words[j]);
for (int j = 4; j < 7; j++)
a.dir.v[2].x[j - 4] = double.Parse(words[j]);
for (int j = 7; j < 11; j++)
a.k[j - 7] = double.Parse(words[j]);
else if (words[1] == "2D" || words[1] == "2d")
for (int j = 2; j < 5; j++)
findNode(ref a.n[j - 2], words[j]);
for (int j = 5; j < 8; j++)
a.k[j - 5] = double.Parse(words[j]);
else if (words[1] == "2dS" || words[1] == "2ds" || words[1] == "2DS" || words[1] == "2Ds")
for (int j = 2; j < 5; j++)
findNode(ref a.n[j - 2], words[j]);
for (int j = 5; j < 8; j++)
a.k[j - 5] = double.Parse(words[j]);
else if (words[1] == "Pier" || words[1] == "PIER" || words[1] == "pier")
for (int j = 2; j < 6; j++)
findNode(ref a.n[j - 2], words[j]);
for (int j = 6; j < 9; j++)
a.k[j - 6] = double.Parse(words[j]);
else if (words[1] == "3D" || words[1] == "3d")
for (int j = 2; j < 8; j++)
findNode(ref a.n[j - 2], words[j]);
for (int j = 8; j < 10; j++)
a.k[j - 8] = double.Parse(words[j]);
public void report(double scale)
Console.WriteLine("mtllib ref.mtl");
for (int i = 0; i < E.Length; i++)
Console.WriteLine("usemtl " + E[i].colour);
Console.WriteLine(E[i].ObjFormat());
public void readResult(string results)
string[] lines = results.Split('\n');
for (int i = 1; i <= N.Length; i++)
string[] words = lines[i].Split('\t', ' ', ',', ';');
for (int j = 1; j < 4; j++)
N[i - 1].disp.x[j - 1] = double.Parse(words[j]);
for (int i = p; i < E.Length + p; i++)
string[] words = lines[i].Split('\t', ' ', ',', ';');
E[i - p].data = double.Parse(words[1]);
String[] colour = new string[7]{"Purple", "Blue", "Cyan", "Green", "Yellow", "Orange", "Red"};
for (int i = 1; i < E.Length; i++)
else if (E[i].data < min)
for (int i = 0; i < E.Length; i++)
int c = Convert.ToInt32(Math.Round((E[i].data - min) / (max - min) * 6));
public static void Main()
string record = @"#Header
#name pos1,2,3 active1,2,3,4,5,6 load1,2,3,4,5,6
n1 0,0,0 x,x,x,x,0,x 0,0,0,0,0,0
n2 0,0,3 0,x,x,x,0,x 1,0,0,0,0,0
n3 3,0,3 n2,x,x,x,0,x 0,0,0,0,0,0
n4 3,0,0 x,x,x,x,0,x 0,0,0,0,0,0
#name type(1D) node1,2 z1,2,3 EA,EIyy,EIzz,GJ
#name type(2D/2dS) node1,2,3 E,v,t
#name type(Pier) node1b,2b,1t,2t EA,EI(in plane),GA
#name type(3D) node1b,2b,3b,1t,2t,3t E,v
C1 1D n1,n2 1,0,0 1e4,8.33,8.33,0
C2 1D n4,n3 1,0,0 1e4,8.33,8.33,0
B1 1D n2,n3 0,0,1 1e4,8.33,8.33,0
string results = @"NodeName Disp(1-6) Reaction(1-6)
n1 0,0,0,0,0.361150313339525,0 -0.496646681610255,0,0,0,0.00896059401909644,0
n2 0.810313755928657,0,0,0,0.0896266819705653,0 -0.00313387962298095,0,-0.9985513072819,0,-0.00262248962317191,0
n3 0.810313755928657,0,0,0,0.0901844772993192,0 0,0,0.9985513072819,0,1.33226762955019E-15,0
n4 0,0,0,0,0.359949164382954,0 -0.500219438766764,0,0,0,-0.00128254368125291,0
ElementName StrainEnergy ForceOrStress@IntPt
C1 0.13566713420957 0,-0.32382197405846,0,0 0,-1.1840392588105,0,0
C2 0.134826310680179 0,-0.315843873638128,0,0 0,-1.18224935529966,0,0
B1 0.134663433074579 0,0.863221986178322,0,0 0,-0.866319609570668,0,0
Struct str = new Struct();
Console.WriteLine(str.N.Length + " Nodes, " + str.E.Length + " Elements");
Console.WriteLine("Scale : ");
double scale = double.Parse(Console.ReadLine());