How to Work with 2D Profiles in .NET

How to Work with 2D Profiles in .NET

Overview

This article shows how to define 2D cross-section profiles and sweep or revolve them into 3D solids using Aspose.3D for .NET.


Step 1 — Install the Package

dotnet add package Aspose.3D.FOSS

Step 2 — Create a Parameterized Profile

Use built-in shapes such as RectangleShape or CircleShape for standard cross-sections:

using Aspose.ThreeD;
using Aspose.ThreeD.Entities;
using Aspose.ThreeD.Profiles;

var scene = new Scene();

// Rectangle profile: 2 units wide, 1 unit tall
var rectProfile = new RectangleShape();
rectProfile.XDim = 2.0;
rectProfile.YDim = 1.0;

// Extrude 5 units along Z
var beam = new LinearExtrusion(rectProfile, 5.0);
beam.Slices = 10;
scene.RootNode.CreateChildNode("beam", beam);

Step 3 — Create a Parameterized L-shaped Profile

LShape produces an L-section beam from dimensional properties:

using Aspose.ThreeD.Profiles;

// L-shaped cross-section structural beam
var lProfile = new LShape();
lProfile.Width     = 0.1;
lProfile.Depth     = 0.2;
lProfile.Thickness = 0.01;

var lBeam = new LinearExtrusion(lProfile, 4.0);
scene.RootNode.CreateChildNode("l_beam", lBeam);

Step 4 — Create a Mirrored Profile

MirroredProfile produces a symmetric cross-section by mirroring a base profile:

using Aspose.ThreeD.Profiles;

// Base profile to mirror
var baseProfile = new RectangleShape();
baseProfile.XDim = 0.5;
baseProfile.YDim = 1.0;

// Mirror to get a symmetric beam flange
var mirrored = new MirroredProfile(baseProfile);

var iBeam = new LinearExtrusion(mirrored, 3.0);
scene.RootNode.CreateChildNode("i_beam", iBeam);

Step 5 — Revolve a Profile into a Solid

RevolvedAreaSolid rotates a profile around an axis to produce a rotationally symmetric solid. Set Shape and AngleEnd on the instance:

var circleProfile = new CircleShape { Radius = 0.5 };
var revolved = new RevolvedAreaSolid();
revolved.Shape    = circleProfile;
revolved.AngleEnd = Math.PI * 2; // full revolution
scene.RootNode.CreateChildNode("sphere", revolved);

Step 6 — Save the Scene

scene.Save("profiles.gltf", FileFormat.GLTF2);
Console.WriteLine("Saved: profiles.gltf");

Troubleshooting

SymptomLikely CauseFix
Extrusion has no visible geometryProfile edges are collinear or zero-areaVerify Edges form a valid closed polygon
Mirrored result is not symmetricMirroredProfile mirrors whatever baseProfile it wraps — there is no separate axis parameter to setPass the correct baseProfile to new MirroredProfile(baseProfile); adjust the base profile itself to get the desired symmetry
Revolved solid is hollow or flatSweep angle is 0 or profile is openUse a closed profile and set angle to Math.PI * 2 for full revolution

Related Resources

See Also

 English