Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion ShapeKernel/Frames/LocalFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,31 @@ public static LocalFrame oGetRotatedFrame(LocalFrame oFrame, float dPhi, Vector3
return oNewFrame;
}

/// <summary>
/// Returns a new LocalFrame positioned at an offset relative to the given reference frame.
/// The offset is interpreted in the reference frame's local coordinate system.
/// Use caution if chaining relative frames as inaccuracies can compound.
/// </summary>
/// <param name="refFrame">The LocalFrame whose local axes define the translation directions</param>
/// <param name="vecLocalOffset">Translation vector in the reference frame's local coordinates</param>
/// <returns>A new LocalFrame translated relative to the reference frame</returns>
public static LocalFrame oGetRelativeFrame(LocalFrame refFrame, Vector3 vecLocalOffset)
{
Vector3 vecRefX = refFrame.vecGetLocalX();
Vector3 vecRefY = refFrame.vecGetLocalY();
Vector3 vecRefZ = refFrame.vecGetLocalZ();

Vector3 vecGlobalOffset =
vecRefX * vecLocalOffset.X
vecRefY * vecLocalOffset.Y +
vecRefZ * vecLocalOffset.Z;

Vector3 vecNewPosition = refFrame.vecGetPosition() + vecGlobalOffset;

return new LocalFrame(vecNewPosition, refFrame.vecGetLocalZ(), refFrame.vecGetLocalX());
}


/// <summary>
/// Compliments local z and local x according to a right-hand system.
/// </summary>
Expand All @@ -212,4 +237,4 @@ public static Vector3 vecGetLocalY(Vector3 vecLocalZ, Vector3 vecLocalX)
}
}
}
}
}