Skip to content

Commit

Permalink
Fix default vector value
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Oscarsson committed Jul 10, 2020
1 parent 022ef85 commit c6e8571
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 45 deletions.
17 changes: 0 additions & 17 deletions src/GenericClasses/DynamoNullArgument.cs

This file was deleted.

126 changes: 98 additions & 28 deletions src/Loads/LineLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,47 +109,122 @@ internal LineLoad(Geometry.Edge _edge, Geometry.FdVector3d f0, Geometry.FdVector

internal void SetStartAndEndForces(Geometry.FdVector3d startForce, Geometry.FdVector3d endForce)
{
Geometry.FdVector3d v0 = startForce.Normalize();
Geometry.FdVector3d v1 = endForce.Normalize();
int par = v0.Parallel(v1);
if (par != 0)
if (startForce.IsZero() && !endForce.IsZero())
{
this.direction = v0;
this.direction = endForce.Normalize();
this.startLoad = 0;
this.endLoad = endForce.Length();
}

else if (!startForce.IsZero() && endForce.IsZero())
{
this.direction = startForce.Normalize();
this.startLoad = startForce.Length();
this.endLoad = par * endForce.Length();
this.endLoad = 0;
}

else if (startForce.IsZero() && endForce.IsZero())
{
throw new System.ArgumentException($"Both StartForce and EndForce are zero vectors. Can't set direction of LineLoad.");
}

// if no zero vectors - check if vectors are parallel
else
{
throw new System.ArgumentException($"Forces must be parallel or antiparallel.");
Geometry.FdVector3d v0 = startForce.Normalize();
Geometry.FdVector3d v1 = endForce.Normalize();
double q0 = startForce.Length();
double q1 = endForce.Length();

int par = v0.Parallel(v1);
if (par != 0)
{
this.direction = v0;
this.startLoad = q0;
this.endLoad = par * q1;
}
else
{
throw new System.ArgumentException($"StartForce and EndForce must be parallel or antiparallel.");
}
}
}

#region dynamo
/// <summary>
/// Create a uniform force line load.
/// </summary>
/// <remarks>Create</remarks>
/// <param name="curve">Curve defining the line load.</param>
/// <param name="force">Force at start and end.</param>
/// <param name="loadCase">LoadCase.</param>
/// <param name="constLoadDir">Bool. Constant load direction? If true direction of load will be constant along action line. If false direction will vary along action line - characteristic direction is in the middle point of line. Optional.</param>
/// <param name="comment">Comment.</param>
[IsVisibleInDynamoLibrary(true)]
public static LineLoad ForceUniform(Autodesk.DesignScript.Geometry.Curve curve, Autodesk.DesignScript.Geometry.Vector force, LoadCase loadCase, [DefaultArgument("true")] bool constLoadDir, string comment = "")
{
// convert geometry
Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc1(curve);
Geometry.FdVector3d _startForce = Geometry.FdVector3d.FromDynamo(force);
Geometry.FdVector3d _endForce = _startForce;

// check zero vector
if (_startForce.IsZero())
{
throw new System.ArgumentException($"Force is zero.");
}

//
return new LineLoad(edge, _startForce, _endForce, loadCase, comment, constLoadDir, false, "force");
}

/// <summary>
/// Create a uniform or non-uniform force line load.
/// </summary>
/// <remarks>Create</remarks>
/// <param name="curve">Curve defining the line load.</param>
/// <param name="startForce">Force at start.</param>
/// <param name="endForce">Force at end. Optional. If undefined line load will be uniform with a force of StartForce.</param>
/// <param name="endForce">Force at end.</param>
/// <param name="loadCase">LoadCase.</param>
/// <param name="constLoadDir">Bool. Constant load direction? If true direction of load will be constant along action line. If false direction will vary along action line - characteristic direction is in the middle point of line. Optional.</param>
/// <param name="comment">Comment.</param>
[IsVisibleInDynamoLibrary(true)]
public static LineLoad Force(Autodesk.DesignScript.Geometry.Curve curve, Autodesk.DesignScript.Geometry.Vector startForce, [DefaultArgument("DynamoNullArgument.GetNull()")] Autodesk.DesignScript.Geometry.Vector endForce, LoadCase loadCase, [DefaultArgument("true")] bool constLoadDir, string comment = "")
public static LineLoad Force(Autodesk.DesignScript.Geometry.Curve curve, Autodesk.DesignScript.Geometry.Vector startForce, Autodesk.DesignScript.Geometry.Vector endForce, LoadCase loadCase, [DefaultArgument("true")] bool constLoadDir, string comment = "")
{
// convert geometry
Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc1(curve);
Geometry.FdVector3d _startForce = Geometry.FdVector3d.FromDynamo(startForce);
Geometry.FdVector3d _endForce;
if (endForce == null)
{
_endForce = _startForce;
}
else
Geometry.FdVector3d _endForce = Geometry.FdVector3d.FromDynamo(endForce);

//
return new LineLoad(edge, _startForce, _endForce, loadCase, comment, constLoadDir, false, "force");
}

/// <summary>
/// Create a uniform moment line load.
/// </summary>
/// <remarks>Create</remarks>
/// <param name="curve">Curve defining the line load.</param>
/// <param name="force">Force (moment) at start and end</param>
/// <param name="loadCase">LoadCase.</param>
/// <param name="constLoadDir">Bool. Constant load direction? If true direction of load will be constant along action line. If false direction will vary along action line - characteristic direction is in the middle point of line. Optional.</param>
/// <param name="comment">Comment.</param>
[IsVisibleInDynamoLibrary(true)]
public static LineLoad MomentUniform(Autodesk.DesignScript.Geometry.Curve curve, Autodesk.DesignScript.Geometry.Vector force, LoadCase loadCase, [DefaultArgument("true")] bool constLoadDir, string comment = "")
{
// convert geometry
Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc1(curve);
Geometry.FdVector3d _startForce = Geometry.FdVector3d.FromDynamo(force);
Geometry.FdVector3d _endForce = _startForce;

// check zero vector
if (_startForce.IsZero())
{
_endForce = Geometry.FdVector3d.FromDynamo(endForce);
throw new System.ArgumentException($"Force is zero.");
}
return new LineLoad(edge, _startForce, _endForce, loadCase, comment, constLoadDir, false, "force");

//
return new LineLoad(edge, _startForce, _endForce, loadCase, comment, constLoadDir, false, "moment");
}

/// <summary>
Expand All @@ -158,24 +233,19 @@ public static LineLoad Force(Autodesk.DesignScript.Geometry.Curve curve, Autodes
/// <remarks>Create</remarks>
/// <param name="curve">Curve defining the line load.</param>
/// <param name="startForce">Force (moment) at start.</param>
/// <param name="endForce">Force (moment) at end. Optional. If undefined line load will be uniform with a force (moment) of StartForce.</param>
/// <param name="endForce">Force (moment) at end.</param>
/// <param name="loadCase">LoadCase.</param>
/// <param name="constLoadDir">Bool. Constant load direction? If true direction of load will be constant along action line. If false direction will vary along action line - characteristic direction is in the middle point of line. Optional.</param>
/// <param name="comment">Comment.</param>
[IsVisibleInDynamoLibrary(true)]
public static LineLoad Moment(Autodesk.DesignScript.Geometry.Curve curve, Autodesk.DesignScript.Geometry.Vector startForce, [DefaultArgument("DynamoNullArgument.GetNull()")] Autodesk.DesignScript.Geometry.Vector endForce, LoadCase loadCase, [DefaultArgument("true")] bool constLoadDir, string comment = "")
public static LineLoad Moment(Autodesk.DesignScript.Geometry.Curve curve, Autodesk.DesignScript.Geometry.Vector startForce, Autodesk.DesignScript.Geometry.Vector endForce, LoadCase loadCase, [DefaultArgument("true")] bool constLoadDir, string comment = "")
{
// convert geometry
Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc1(curve);
Geometry.FdVector3d _startForce = Geometry.FdVector3d.FromDynamo(startForce);
Geometry.FdVector3d _endForce;
if (endForce == null)
{
_endForce = _startForce;
}
else
{
_endForce = Geometry.FdVector3d.FromDynamo(endForce);
}
Geometry.FdVector3d _endForce = Geometry.FdVector3d.FromDynamo(endForce);

//
return new LineLoad(edge, _startForce, _endForce, loadCase, comment, constLoadDir, false, "moment");
}

Expand Down

0 comments on commit c6e8571

Please sign in to comment.