Skip to content

Commit

Permalink
fix(element): add BeamElement to generalize Element
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvilans committed Oct 22, 2020
1 parent 406a49d commit 2f67485
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 19 deletions.
4 changes: 2 additions & 2 deletions GluLamb/Structure/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public Connection(Element eleA, Element eleB, double positionA, double positionB
public Line Discretize()
{
return new Line(
ElementA.Beam.Centreline.PointAt(ParameterA),
ElementB.Beam.Centreline.PointAt(ParameterB));
ElementA.GetConnectionPoint(ParameterA),
ElementB.GetConnectionPoint(ParameterB));
}
}
}
65 changes: 48 additions & 17 deletions GluLamb/Structure/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ namespace GluLamb
public class Element
{
public string Name;
public Glulam Beam;
public List<Connection> Connections;
private Plane m_plane;
protected Plane m_plane;

public Element(Glulam g, string name = "")
public Element(string name = "")
{
Beam = g;
Connections = new List<Connection>();
Name = name;
m_plane = Beam.GetPlane(Beam.Centreline.Domain.Mid);
m_plane = Plane.WorldXY;
}

public Element(Plane handle, string name = "")
{
Connections = new List<Connection>();
Name = name;
m_plane = handle;
}

public Plane Handle
Expand All @@ -34,20 +39,14 @@ public Plane Handle
}
}

public Polyline Discretize(double length)
public virtual GeometryBase Discretize(double length)
{
var t = Beam.Centreline.DivideByLength(length, true).ToList();
foreach (var conn in Connections)
{
if (conn.ElementA == this)
t.Add(conn.ParameterA);
else if (conn.ElementB == this)
t.Add(conn.ParameterB);
}

t.Sort();
return null;
}

return new Polyline(t.Select(x => Beam.Centreline.PointAt(x)));
public virtual Point3d GetConnectionPoint(double t)
{
return m_plane.Origin;
}

public Element GetConnected(int index)
Expand All @@ -71,4 +70,36 @@ public Element GetConnected(int index)
}
}

public class BeamElement : Element
{
public BeamBase Beam;

public BeamElement(BeamBase beam)
{
Beam = beam;
m_plane = Beam.GetPlane(Beam.Centreline.Domain.Mid);
}

public override GeometryBase Discretize(double length)
{
var t = Beam.Centreline.DivideByLength(length, true).ToList();
foreach (var conn in Connections)
{
if (conn.ElementA == this)
t.Add(conn.ParameterA);
else if (conn.ElementB == this)
t.Add(conn.ParameterB);
}

t.Sort();

return new PolylineCurve(t.Select(x => Beam.Centreline.PointAt(x)));
}

public override Point3d GetConnectionPoint(double t)
{
return Beam.Centreline.PointAt(t);
}
}

}
34 changes: 34 additions & 0 deletions GluLamb/Structure/Structure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,40 @@ public Structure()
Elements = new List<Element>();
}

public static Structure FromBeamElements(List<BeamElement> elements, double searchDistance, double overlapDistance)
{
int counter = 0;
foreach (var ele in elements)
{
ele.Name = string.Format("Element_{0:000}", counter);
counter++;
}

var structure = new Structure();

structure.Elements.AddRange(elements);

for (int i = 0; i < elements.Count - 1; ++i)
{
for (int j = i + 1; j < elements.Count; ++j)
{
var intersections = Rhino.Geometry.Intersect.Intersection.CurveCurve(elements[i].Beam.Centreline, elements[j].Beam.Centreline, searchDistance, overlapDistance);

foreach (var intersection in intersections)
{
structure.Connections.Add(
Connection.Connect(
elements[i], elements[j],
intersection.ParameterA, intersection.ParameterB,
string.Format("{0}-{1}", elements[i].Name, elements[j].Name))
);
}
}
}

return structure;
}

public List<object> Discretize(double length)
{
var segments = new List<object>();
Expand Down

0 comments on commit 2f67485

Please sign in to comment.