Show / Hide Table of Contents

    Class Grid1d

    Represents a "1-dimensional grid", akin to a number line that can be subdivided.

    Examples
    // Create a 1d Grid from a line
    var line = new Line(new Vector3(5, 0, 0), new Vector3(60, 0, 0));
    var grid = new Grid1d(line);
    
    // Divide the grid into sections of length 10, and leave remainders
    // at both ends
    grid.DivideByFixedLength(10, FixedDivisionMode.RemainderAtBothEnds);
    
    // Take the second grid segment and subdivide it
    // into 5 equal length segments
    grid[1].DivideByCount(5);
    
    // Take the third grid segment and subdivide it into
    // segments of approximate length 3
    grid[2].DivideByApproximateLength(3);
    
    // Take the fourth grid segment and subdivide it by a repeating pattern
    var pattern = new[] { 1.0, 1.5 };
    grid[3].DivideByPattern(pattern);
    
    // Retrieve all bottom-level cells.
    // Note that grid.Cells gets the top-level cells only, and
    // grid.GetCells() recursively gets the bottom-level individual cells.
    var cells = grid.GetCells();
    
    // Get lines representing each cell
    var lines = cells.Select(c => c.GetCellGeometry()).OfType<Line>();
    
    // Create walls from lines, and assign a random color material
    List<Wall> walls = new List<Wall>();
    var rand = new Random();
    foreach (var wallLine in lines)
    {
        var color = new Color(rand.NextDouble(), rand.NextDouble(), rand.NextDouble(), 1.0);
        walls.Add(new StandardWall(wallLine, 0.1, 3.0, new Material(color.ToString(), color, 0, 0, null, false, false)));
    }
    
    // Create rectangles from top-level grid cells
    var topLevelCells = grid.Cells.Select(c => c.GetCellGeometry()).OfType<Line>();
    var cellRects = new List<ModelCurve>();
    foreach (var topLevelCell in topLevelCells)
    {
        var rect = Polygon.Rectangle(topLevelCell.Start - new Vector3(0, 2, 0), topLevelCell.End + new Vector3(0, 2, 0));
        cellRects.Add(new ModelCurve(rect));
    }
    
    Inheritance
    System.Object
    Grid1d
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Elements.Spatial
    Assembly: Hypar.Elements.dll
    Syntax
    [JsonConverter(typeof(JsonInheritanceConverter), new object[]{"discriminator"})]
    public class Grid1d

    Constructors

    Grid1d(Domain1d)

    Construct a 1D grid from a numerical domain. The geometry will be assumed to lie along the X axis.

    Declaration
    public Grid1d(Domain1d domain)
    Parameters
    Type Name Description
    Domain1d domain

    The 1-dimensional domain for the grid extents.

    Grid1d(BoundedCurve)

    Construct a 1D grid from a curve.

    Declaration
    public Grid1d(BoundedCurve curve)
    Parameters
    Type Name Description
    BoundedCurve curve

    The curve from which to generate the grid.

    Grid1d(Grid1d)

    Construct a 1D Grid from another 1D Grid

    Declaration
    public Grid1d(Grid1d other)
    Parameters
    Type Name Description
    Grid1d other

    Grid1d(Double)

    Default constructor with optional length parameter

    Declaration
    public Grid1d(double length = 1)
    Parameters
    Type Name Description
    System.Double length

    Length of the grid domain

    Properties

    Cells

    Child cells of this Grid. If null, this Grid is a complete cell with no subdivisions.

    Declaration
    [JsonProperty("Cells", NullValueHandling = NullValueHandling.Ignore)]
    public List<Grid1d> Cells { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<Grid1d>

    Curve

    The base curve at the top level of this grid.

    Declaration
    [JsonIgnore]
    public BoundedCurve Curve { get; }
    Property Value
    Type Description
    BoundedCurve

    Domain

    Numerical domain of this Grid

    Declaration
    public Domain1d Domain { get; }
    Property Value
    Type Description
    Domain1d

    IsSingleCell

    Returns true if this 1D Grid has no subdivisions / sub-grids.

    Declaration
    public bool IsSingleCell { get; }
    Property Value
    Type Description
    System.Boolean

    Item[Int32]

    Retrieve a cell by index

    Declaration
    [JsonIgnore]
    public Grid1d this[int i] { get; }
    Parameters
    Type Name Description
    System.Int32 i

    The index

    Property Value
    Type Description
    Grid1d

    A Grid1d representing the selected cell/segment.

    Type

    An optional type designation for this cell.

    Declaration
    public string Type { get; set; }
    Property Value
    Type Description
    System.String

    Methods

    ClosestPosition(Vector3)

    Get the position along the grid's domain closest to a supplied point.

    Declaration
    public double ClosestPosition(Vector3 point)
    Parameters
    Type Name Description
    Vector3 point
    Returns
    Type Description
    System.Double

    DivideByApproximateLength(Double, EvenDivisionMode)

    Divide a grid by an approximate length. The length will be adjusted to generate whole-number subdivisions, governed by an optional DivisionMode.

    Declaration
    public void DivideByApproximateLength(double targetLength, EvenDivisionMode divisionMode = EvenDivisionMode.Nearest)
    Parameters
    Type Name Description
    System.Double targetLength

    The approximate length by which to divide the grid.

    EvenDivisionMode divisionMode

    Whether to permit any size cell, or only larger or smaller cells by rounding up or down.

    DivideByCount(Int32)

    Divide the grid into N even subdivisions. Grids that are already subdivided will fail.

    Declaration
    public void DivideByCount(int n)
    Parameters
    Type Name Description
    System.Int32 n

    Number of subdivisions

    DivideByFixedLength(Double, FixedDivisionMode, Int32)

    Divide a grid by constant length subdivisions, with a variable division mode to control how leftover space is handled.

    Declaration
    public void DivideByFixedLength(double length, FixedDivisionMode divisionMode = FixedDivisionMode.RemainderAtEnd, int sacrificialPanels = 0)
    Parameters
    Type Name Description
    System.Double length

    The division length

    FixedDivisionMode divisionMode

    How to handle leftover / partial remainder panels

    System.Int32 sacrificialPanels

    How many full length panels to sacrifice to make remainder panels longer.

    DivideByFixedLengthFromPoint(Double, Vector3)

    Divide a grid by constant length subdivisions, starting from a point location.

    Declaration
    public void DivideByFixedLengthFromPoint(double length, Vector3 point)
    Parameters
    Type Name Description
    System.Double length

    The length of subdivisions

    Vector3 point

    The point at which to begin subdividing.

    DivideByFixedLengthFromPosition(Double, Double)

    Divide a grid by constant length subdivisions, starting from a position.

    Declaration
    public void DivideByFixedLengthFromPosition(double length, double position)
    Parameters
    Type Name Description
    System.Double length

    The length of subdivisions

    System.Double position

    The position along the domain at which to begin subdividing.

    DivideByPattern(IList<Double>, PatternMode, FixedDivisionMode)

    Divide a grid by a pattern of lengths. Type names will be automatically generated, repetition will be governed by PatternMode, and remainder handling will be governed by DivisionMode.

    Declaration
    public void DivideByPattern(IList<double> lengthPattern, PatternMode patternMode = PatternMode.Cycle, FixedDivisionMode divisionMode = FixedDivisionMode.RemainderAtEnd)
    Parameters
    Type Name Description
    System.Collections.Generic.IList<System.Double> lengthPattern

    A pattern of lengths to apply to the grid

    PatternMode patternMode

    How to apply/repeat the pattern

    FixedDivisionMode divisionMode

    How to handle leftover/remainder length

    DivideByPattern(IList<(String typeName, Double length)>, PatternMode, FixedDivisionMode)

    Divide a grid by a pattern of named lengths. Repetition will be governed by PatternMode, and remainder handling will be governed by DivisionMode.

    Declaration
    public void DivideByPattern(IList<(string typeName, double length)> lengthPattern, PatternMode patternMode = PatternMode.Cycle, FixedDivisionMode divisionMode = FixedDivisionMode.RemainderAtEnd)
    Parameters
    Type Name Description
    System.Collections.Generic.IList<System.ValueTuple<System.String, System.Double>> lengthPattern

    A pattern of lengths to apply to the grid

    PatternMode patternMode

    How to apply/repeat the pattern

    FixedDivisionMode divisionMode

    How to handle leftover/remainder length

    FindCellAtPosition(Double)

    Retrieve the grid cell (as a Grid1d) at a length along the domain.

    Declaration
    public Grid1d FindCellAtPosition(double pos)
    Parameters
    Type Name Description
    System.Double pos

    The position in the grid's domain to find

    Returns
    Type Description
    Grid1d

    The cell at this position, if found, or this grid if it is a single cell.

    GetCellDomains(Boolean)

    Get domain parameters at the ends and in-between all cells.

    Declaration
    public List<double> GetCellDomains(bool recursive = false)
    Parameters
    Type Name Description
    System.Boolean recursive

    If true, domains will be retrieved from child cells as well.

    Returns
    Type Description
    System.Collections.Generic.List<System.Double>

    A list of double representing the domain across cells.

    GetCellGeometry()

    Retrieve geometric representation of a cell (currently just a line)

    Declaration
    public BoundedCurve GetCellGeometry()
    Returns
    Type Description
    BoundedCurve

    A curve representing the extents of this grid / cell.

    GetCells()

    Retrieve all grid segment cells recursively. For just top-level cells, get the Cells property.

    Declaration
    public List<Grid1d> GetCells()
    Returns
    Type Description
    System.Collections.Generic.List<Grid1d>

    A list of all the bottom-level cells / child cells of this grid.

    GetCellSeparators(Boolean)

    Get the points at the ends and in-between all cells.

    Declaration
    public List<Vector3> GetCellSeparators(bool recursive = false)
    Parameters
    Type Name Description
    System.Boolean recursive

    If true, separators will be retrieved from child cells as well.

    Returns
    Type Description
    System.Collections.Generic.List<Vector3>

    A list of Vector3d points representing the boundaries between cells.

    SplitAtOffset(Double, Boolean, Boolean)

    Split a cell at a relative position measured from its domain start or end.

    Declaration
    public void SplitAtOffset(double position, bool fromEnd = false, bool ignoreOutsideDomain = false)
    Parameters
    Type Name Description
    System.Double position

    The relative position at which to split.

    System.Boolean fromEnd

    If true, measure the position from the end rather than the start

    System.Boolean ignoreOutsideDomain

    If true, splits at offsets outside the domain will be silently ignored.

    SplitAtOffsets(IEnumerable<Double>, Boolean)

    Split a cell at a list of relative positions measured from its domain start or end.

    Declaration
    public void SplitAtOffsets(IEnumerable<double> positions, bool fromEnd = false)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<System.Double> positions

    The relative positions at which to split.

    System.Boolean fromEnd

    If true, measure the position from the end rather than the start

    SplitAtParameter(Double)

    Split the grid at a normalized parameter from 0 to 1 along its domain.

    Declaration
    public void SplitAtParameter(double t)
    Parameters
    Type Name Description
    System.Double t

    The parameter at which to split.

    SplitAtParameters(IEnumerable<Double>)

    Split the grid at a list of normalized parameters from 0 to 1 along its domain.

    Declaration
    public void SplitAtParameters(IEnumerable<double> parameters)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<System.Double> parameters

    A list of parameters at which to split the grid.

    SplitAtPoint(Vector3)

    Split the grid at a point in world space. Note that for curved grids an approximate point will be used.

    Declaration
    public void SplitAtPoint(Vector3 point)
    Parameters
    Type Name Description
    Vector3 point

    SplitAtPoints(IEnumerable<Vector3>)

    Split the grid at points in world space. Note that for curved grids an approximate point will be used.

    Declaration
    public void SplitAtPoints(IEnumerable<Vector3> points)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<Vector3> points

    The points at which to split.

    SplitAtPosition(Double)

    Split the grid at a fixed position from the start or end

    Declaration
    public void SplitAtPosition(double position)
    Parameters
    Type Name Description
    System.Double position

    The length along the grid at which to split.

    SplitAtPositions(IEnumerable<Double>)

    Split the grid at a list of fixed positions from the start or end

    Declaration
    public void SplitAtPositions(IEnumerable<double> positions)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<System.Double> positions

    The lengths along the grid at which to split.