Cách làm việc với các hồ sơ 2D trong .NET

Cách làm việc với các hồ sơ 2D trong .NET

Cách làm việc với các hồ sơ 2D trong .NET

Bài viết này trình bày cách định nghĩa các hồ sơ mặt cắt 2D và quét hoặc quay chúng thành các khối 3D bằng cách sử dụng Aspose.3D cho .NET.


Bước 1 — Cài đặt gói

dotnet add package Aspose.3D.FOSS

Bước 2 — Tạo hồ sơ có tham số

Sử dụng các hình dạng tích hợp sẵn như RectangleShape hoặc CircleShape cho các mặt cắt tiêu chuẩn:

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);

Bước 3 — Tạo hồ sơ dạng chữ L có tham số

LShape tạo ra dầm dạng góc L từ các thuộc tính kích thước:

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);

Bước 4 — Tạo một hồ sơ phản chiếu

MirroredProfile tạo ra một mặt cắt ngang đối xứng bằng cách phản chiếu một hồ sơ cơ sở:

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);

Bước 5 — Quay hồ sơ thành khối rắn

RevolvedAreaSolid quay một hồ sơ quanh trục để tạo ra một khối rắn đối xứng quay. Đặt Shape và AngleEnd trên thể hiện:

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);

Bước 6 — Lưu cảnh

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

Troubleshooting

SymptomNguyên nhân có thểSửa
Phép đùn không có hình học hiển thịCác cạnh của profile thẳng hàng hoặc có diện tích bằng khôngXác minh Edges tạo thành một đa giác đóng hợp lệ
Kết quả phản chiếu không đối xứngMirroredProfile phản chiếu bất kỳ baseProfile nào nó bao bọc — không có tham số trục riêng để đặtChuyển baseProfile đúng cho new MirroredProfile(baseProfile); điều chỉnh chính profile cơ bản để đạt được độ đối xứng mong muốn
Khối quay tròn là rỗng hoặc phẳngGóc quét bằng 0 hoặc profile mởSử dụng profile đóng và đặt góc thành Math.PI * 2 để quay trọn vòng

Tài nguyên liên quan

Xem thêm

 Tiếng Việt