'2D Jagged array size change in c#

enter image description hereI am planning to calculate 3d coordinate points using vector3d. To find segmented points for a circle I thought i need to use jagged array to find the points. Can we change the size of the jagged array after initialization. In that case how?

I tried like this Vector3D[VerticesOfProfile][VerticeOfTrajetory] myVertices = new Vector3D[n][m]

I don't want to pre initialize n and m before as they vary based on size of the circle

enter image description here

enter image description here



Solution 1:[1]

The way I would write this function would be something like this pseudo-code

var sweepPoints = new List<Vector3D[]>();

// Use 32 segments along the path, this could be computed depending on curvature if needed.
for(var i = 0; i < 32; i++){
    var t = i / 32d; // compute a 't' value in range 0-1 along the path;

    // Assuming you have something like a bezier-representation of a path
    // You would need the position and direction along the path.
    var pos = path.GetPositionAtT(t);
    var direction = path.GetDirectionAtT(t);

    // Create a circle from a position, direction and radius
    var circle= new Circle3D(pos , direction , 3);
    
    // Create 16 points around the circumference, you could compute the number of points from the radius if needed
    var circlePoints = circle.Segment(16);

    sweepPoints.Add(transform.Transform(circlePoints));
}

This does not technically need any dynamic arrays (i.e. List<T>) but it may make the code a bit more readable.

Also note that doing such sweep using an arbitrary shape and path will likely involve a fair amount of 3D math, so a good library and some basic knowledge of linear algebra will be very helpful.

In the simpler case of generating points describing a cylinder, as in your image, you know that you need two 'rings' of points, so this scenario should be fairly easy to handle. Just create a 3D-circle for each end-face and generate segments for each of the circles.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JonasH