public void GeneratePrincipalStressLines() { PrincipalStressLinesX = new List <Line>(); PrincipalStressLinesY = new List <Line>(); for (int i = 0; i < NumberOfElements; i++) { Vector3D e1, e2, e3; ShellElement ele = elements[i]; ele.GetLocalCoordinateSystem(out e1, out e2, out e3); double L = ele.GetPerimeterLength(); double scaler = 0.1 * L; Point3d C = ele.Centroid.ToRhinoPoint3d(); Transform T = Transform.Rotation(PrincipalAngles[i], e3.ToRhinoVector3d(), C); //Vector3d p1 = e1.ToRhinoVector3d(); //Vector3d p2 = e2.ToRhinoVector3d(); //p1.Transform(T); //p2.Transform(T); Line X = new Line(C - scaler * e1.ToRhinoVector3d(), C + scaler * e1.ToRhinoVector3d()); Line Y = new Line(C - scaler * e2.ToRhinoVector3d(), C + scaler * e2.ToRhinoVector3d()); X.Transform(T); Y.Transform(T); PrincipalStressLinesX.Add(X); PrincipalStressLinesY.Add(Y); } }
public void AlignMaterialAxisWithCurves(Curve[] dirCurves) { for (int i = 0; i < elements.Count; i++) { ShellElement elem = elements[i]; Point3d centroid = elem.Centroid.ToRhinoPoint3d(); double t; Curve dirCurve = FindClosestCurve(dirCurves, centroid, out t); Vector3d dirVec = dirCurve.TangentAt(t); Vector3D e1_, e2_, e3_; elem.GetLocalCoordinateSystem(out e1_, out e2_, out e3_); Vector3d e1 = e1_.ToRhinoVector3d(), e2 = e2_.ToRhinoVector3d(), e3 = e3_.ToRhinoVector3d(); Plane P = new Plane(centroid, e3); double alpha = Vector3d.VectorAngle(e1, dirVec, P); if (Double.IsNaN(alpha) || Double.IsInfinity(alpha) || Math.Abs(alpha) > Math.PI * 2) { SetDefaultMaterialOrientationAngle(i); } else { elem.MaterialOrientationAngle = (alpha / (2 * Math.PI)) * 360; } } }
public static StructureType CreateFromMesh(Mesh mesh) { List <Node> nodes = new List <Node>(mesh.Vertices.Count); for (int i = 0; i < mesh.Vertices.Count; i++) { Node node = new Node(mesh.Vertices[i].X, mesh.Vertices[i].Y, mesh.Vertices[i].Z, i); nodes.Add(node); } List <ShellElement> elements = new List <ShellElement>(mesh.Faces.Count); for (int i = 0; i < mesh.Faces.Count; i++) { int A = mesh.Faces[i].A; int B = mesh.Faces[i].B; int C = mesh.Faces[i].C; List <Node> elementNodes = new List <Node> { nodes[A], nodes[B], nodes[C] }; ShellElement element = new ShellElement(elementNodes, i); elements.Add(element); } StructureType S = new StructureType(nodes, elements); S.mesh = mesh; return(S); }
public void SetDefaultMaterialOrientationAngle(int elementIndex) { Vector3D e1, e2, e3, C; ShellElement ele = elements[elementIndex]; ele.GetLocalCoordinateSystem(out e1, out e2, out e3); C = ele.Centroid; Plane P = new Plane(C.ToRhinoPoint3d(), e3.ToRhinoVector3d()); double alpha = Vector3d.VectorAngle(e1.ToRhinoVector3d(), Vector3d.XAxis, P); if (Double.IsNaN(alpha) || Double.IsInfinity(alpha) || Math.Abs(alpha) > Math.PI * 2) { alpha = Vector3d.VectorAngle(e1.ToRhinoVector3d(), Vector3d.YAxis, P); } ele.MaterialOrientationAngle = (alpha / (2 * Math.PI)) * 360; }
private void Add_Element_Click(object sender, RoutedEventArgs e) { try { double _length, _height, _thickness, _sizeX, _sizeY, _xIni, _yIni, _zIni; int _mat, _layers, signLength, signHeight; _length = Double.Parse(txt_length.Text); _height = Double.Parse(txt_height.Text); _thickness = Double.Parse(txt_thickness.Text); _sizeX = Double.Parse(txt_sizeLength.Text); _sizeY = Double.Parse(txt_sizeHeight.Text); _mat = Int32.Parse(txt_mat.Text); _xIni = Double.Parse(txt_xIni.Text); _yIni = Double.Parse(txt_yIni.Text); _zIni = Double.Parse(txt_zIni.Text); _layers = Int32.Parse(txt_layer.Text); Vector3D _iniVec, _lengthVec, _heightVec; _iniVec = new Vector3D(_xIni, _yIni, _zIni); //gets the sign of the length of the element if (_length < 0) { signLength = -1; } else { signLength = 1; } //gets the sign of the height of the element if (_height < 0) { signHeight = -1; } else { signHeight = 1; } //sets the length direction and height direction in terms of vectors if (rd_xLeng.IsChecked == true) { _lengthVec = new Vector3D(1, 0, 0); } else if (rd_yLeng.IsChecked == true) { _lengthVec = new Vector3D(0, 1, 0); } else { _lengthVec = new Vector3D(0, 0, 1); } if (rd_xHeight.IsChecked == true) { _heightVec = new Vector3D(1, 0, 0); } else if (rd_yHeight.IsChecked == true) { _heightVec = new Vector3D(0, 1, 0); } else { _heightVec = new Vector3D(0, 0, 1); } double eleNumberDir1 = Math.Abs(_length) / _sizeX; double eleNumberDir2 = Math.Abs(_height) / _sizeY; double nodeNumberDir1 = eleNumberDir1 * 2 + 1; double nodeNumberDir2 = eleNumberDir2 * 2 + 1; int count = MainWindow.nodeList.Count; //Create the nodes for (int i = 0; i < nodeNumberDir2; i++) //Iterate over height { for (int j = 0; j < nodeNumberDir1; j++) //iterate over length (the order is reversed so that the numbering comes in rows instead of columns { double xPos, yPos, zPos; xPos = _iniVec.X + signLength * j * _lengthVec.X * (_sizeX / 2) + signHeight * i * _heightVec.X * (_sizeY / 2); yPos = _iniVec.Y + signLength * j * _lengthVec.Y * (_sizeX / 2) + signHeight * i * _heightVec.Y * (_sizeY / 2); zPos = _iniVec.Z + signLength * j * _lengthVec.Z * (_sizeX / 2) + signHeight * i * _heightVec.Z * (_sizeY / 2); if (Node.FindNodeByCoordinates(xPos, yPos, zPos, new List <Node>(MainWindow.nodeList)) == null) { Node n = new Node(count + 1, new Point3D(xPos, yPos, zPos)); MainWindow.nodeList.Add(n); MainWindow.myModel3DGroup.Children.Add(DrawingHelper.Draw3DCube(Configuration.nodeSize * Configuration.zoomParam, n.Point, Configuration.nodeColor)); count++; } } /* this is for the 8-node element * if (i % 2 == 0) //divide by 2 to know in which row of the nodes we are, if it is on the row with 3 nodes per element or on the row with 2 nodes per element * { * for (int j = 0; j < nodeNumberDir1; j++) //iterate over length (the order is reversed so that the numbering comes in rows instead of columns * { * double xPos, yPos, zPos; * xPos = _iniVec.X + j * _lengthVec.X * (_size / 2) + i * _heightVec.X * (_size / 2); * yPos = _iniVec.Y + j * _lengthVec.Y * (_size / 2) + i * _heightVec.Y * (_size / 2); * zPos = _iniVec.Z + j * _lengthVec.Z * (_size / 2) + i * _heightVec.Z * (_size / 2); * Node n = new Node(count + 1, new Point3D(xPos, yPos, zPos)); * MainWindow.nodeList.Add(n); * MainWindow.myModel3DGroup.Children.Add(DrawingHelper.Draw3DCube(nodeSize, n.Point, Colors.Black)); * count++; * } * } else * { * for (int j = 0; j < nodeNumberDir1 - eleNumberDir1; j++) //iterate over the row of nodes that has lower number of nodess on the 8-node element model * { * double xPos, yPos, zPos; * xPos = _iniVec.X + j * _lengthVec.X * (_size) + i * _heightVec.X * (_size / 2); * yPos = _iniVec.Y + j * _lengthVec.Y * (_size) + i * _heightVec.Y * (_size / 2); * zPos = _iniVec.Z + j * _lengthVec.Z * (_size) + i * _heightVec.Z * (_size / 2); * Node n = new Node(count + 1, new Point3D(xPos, yPos, zPos)); * MainWindow.nodeList.Add(n); * MainWindow.myModel3DGroup.Children.Add(DrawingHelper.Draw3DCube(nodeSize, n.Point, Colors.Black)); * count++; * } * } */ } List <Node> nodeList = new List <Node>(MainWindow.nodeList); List <Material> materialList = new List <Material>(MainWindow.materialList); //Create the Elements int countEle = MainWindow.shellList.Count; for (int i = 0; i < eleNumberDir2; i++) //for each element { for (int j = 0; j < eleNumberDir1; j++) { Vector3D pos = _iniVec; Node n1 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); pos += _sizeX * signLength * _lengthVec; Node n2 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); pos += _sizeY * signHeight * _heightVec; Node n3 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); pos -= _sizeX * signLength * _lengthVec; Node n4 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); pos = pos - _sizeY * signHeight * _heightVec + (_sizeX / 2) * signLength * _lengthVec; Node n5 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); pos = pos + (_sizeX / 2) * signLength * _lengthVec + (_sizeY / 2) * signHeight * _heightVec; Node n6 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); pos = pos - (_sizeX / 2) * signLength * _lengthVec + (_sizeY / 2) * signHeight * _heightVec; Node n7 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); pos = pos - (_sizeX / 2) * signLength * _lengthVec - (_sizeY / 2) * signHeight * _heightVec; Node n8 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); pos = pos + (_sizeX / 2) * signLength * _lengthVec; Node n9 = Node.FindNodeByCoordinates(pos.X, pos.Y, pos.Z, nodeList); //adds an element to the element list ShellElement ele = new ShellElement(countEle + 1, n1, n2, n3, n4, n5, n6, n7, n8, n9, _thickness, _layers, materialList[_mat - 1]); countEle++; MainWindow.shellList.Add(ele); //draws the element on the viewModel3D in the mainWindow MainWindow.myModel3DGroup.Children.Add(DrawingHelper.Draw3DPanel(ele, Configuration.shellEleColor, false, MainWindow.dispList, Configuration.zoomParam)); _iniVec += _sizeX * signLength * _lengthVec; } _iniVec.X = _xIni; _iniVec.Y = _yIni; _iniVec.Z = _zIni; _iniVec += (i + 1) * _sizeY * signHeight * _heightVec; } } catch { MessageBox.Show("An error has occurred and the shell elements could not be created. Please check your inputs and try again", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }