or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

analysis-algorithms.mdapplications.mdcolors-visual.mdcore-objects.mdfile-io.mdindex.mdplotting-visualization.mdshape-generation.mdtransformations-geometry.mdui-components.md

shape-generation.mddocs/

0

# Shape Generation

1

2

Comprehensive library of 3D shape primitives, geometric constructions, and procedural generation tools. Vedo provides an extensive collection of shapes ranging from basic geometric primitives to complex curves, text rendering, and specialized visualization objects.

3

4

## Capabilities

5

6

### Basic Geometric Primitives

7

8

Fundamental 3D shapes that serve as building blocks for complex visualizations.

9

10

```python { .api }

11

class Sphere:

12

"""

13

Create a spherical mesh.

14

15

Parameters:

16

- pos: tuple, default (0, 0, 0)

17

Center position coordinates

18

- r: float, default 1

19

Sphere radius

20

- res: int, default 24

21

Resolution (number of subdivisions)

22

- quads: bool, default False

23

Use quad faces instead of triangles

24

- c: str or tuple, default "red"

25

Color specification

26

- alpha: float, default 1

27

Transparency value

28

"""

29

def __init__(self, pos=(0, 0, 0), r=1, res=24, quads=False, c="red", alpha=1): ...

30

31

class Box:

32

"""

33

Create a box/rectangular mesh.

34

35

Parameters:

36

- pos: tuple, default (0, 0, 0)

37

Center position coordinates

38

- length: float, default 1

39

Size along x-axis

40

- width: float, default 1

41

Size along y-axis

42

- height: float, default 1

43

Size along z-axis

44

- c: str or tuple, default "gold"

45

Color specification

46

- alpha: float, default 1

47

Transparency value

48

"""

49

def __init__(self, pos=(0, 0, 0), length=1, width=1, height=1, c="gold", alpha=1): ...

50

51

class Cylinder:

52

"""

53

Create a cylindrical mesh.

54

55

Parameters:

56

- pos: tuple, default (0, 0, 0)

57

Center position coordinates

58

- r: float, default 1

59

Cylinder radius

60

- height: float, default 2

61

Cylinder height

62

- axis: tuple, default (0, 0, 1)

63

Cylinder axis direction

64

- res: int, default 24

65

Resolution around circumference

66

- c: str or tuple, default "teal"

67

Color specification

68

- alpha: float, default 1

69

Transparency value

70

"""

71

def __init__(self, pos=(0, 0, 0), r=1, height=2, axis=(0, 0, 1), res=24, c="teal", alpha=1): ...

72

73

class Cone:

74

"""

75

Create a conical mesh.

76

77

Parameters:

78

- pos: tuple, default (0, 0, 0)

79

Base center position

80

- r: float, default 1

81

Base radius

82

- height: float, default 2

83

Cone height

84

- axis: tuple, default (0, 0, 1)

85

Cone axis direction

86

- res: int, default 24

87

Resolution around circumference

88

- c: str or tuple, default "dg"

89

Color specification

90

- alpha: float, default 1

91

Transparency value

92

"""

93

def __init__(self, pos=(0, 0, 0), r=1, height=2, axis=(0, 0, 1), res=24, c="dg", alpha=1): ...

94

```

95

96

### Advanced 3D Shapes

97

98

More complex geometric shapes for specialized visualization needs.

99

100

```python { .api }

101

class Torus:

102

"""

103

Create a toroidal mesh.

104

105

Parameters:

106

- pos: tuple, default (0, 0, 0)

107

Center position coordinates

108

- r: float, default 1

109

Major radius (center to tube center)

110

- thickness: float, default 0.2

111

Minor radius (tube thickness)

112

- res: int, default 24

113

Resolution around major circumference

114

- c: str or tuple, default "yellow"

115

Color specification

116

- alpha: float, default 1

117

Transparency value

118

"""

119

def __init__(self, pos=(0, 0, 0), r=1, thickness=0.2, res=24, c="yellow", alpha=1): ...

120

121

class Ellipsoid:

122

"""

123

Create an ellipsoidal mesh.

124

125

Parameters:

126

- pos: tuple, default (0, 0, 0)

127

Center position coordinates

128

- axis1: float, default 1

129

Semi-axis length along x

130

- axis2: float, default 1

131

Semi-axis length along y

132

- axis3: float, default 1

133

Semi-axis length along z

134

- res: int, default 24

135

Surface resolution

136

- c: str or tuple, default "cyan"

137

Color specification

138

- alpha: float, default 1

139

Transparency value

140

"""

141

def __init__(self, pos=(0, 0, 0), axis1=1, axis2=1, axis3=1, res=24, c="cyan", alpha=1): ...

142

143

class Paraboloid:

144

"""

145

Create a paraboloid surface.

146

147

Parameters:

148

- pos: tuple, default (0, 0, 0)

149

Center position coordinates

150

- height: float, default 1

151

Paraboloid height

152

- res: int, default 50

153

Surface resolution

154

- c: str or tuple, default "cyan"

155

Color specification

156

- alpha: float, default 1

157

Transparency value

158

"""

159

def __init__(self, pos=(0, 0, 0), height=1, res=50, c="cyan", alpha=1): ...

160

```

161

162

### Lines and Curves

163

164

Linear and curved objects for creating paths, connections, and smooth curves.

165

166

```python { .api }

167

class Line:

168

"""

169

Create a line object from points.

170

171

Parameters:

172

- p0: array-like

173

Starting point or list of points

174

- p1: array-like, optional

175

Ending point (if p0 is single point)

176

- res: int, default 1

177

Line resolution/subdivisions

178

- lw: float, default 1

179

Line width

180

- c: str or tuple, default "red"

181

Color specification

182

- alpha: float, default 1

183

Transparency value

184

"""

185

def __init__(self, p0, p1=None, res=1, lw=1, c="red", alpha=1): ...

186

187

class DashedLine:

188

"""

189

Create a dashed line visualization.

190

191

Parameters:

192

- p0: array-like

193

Starting point

194

- p1: array-like

195

Ending point

196

- spacing: float, default 0.1

197

Spacing between dashes

198

- lw: float, default 2

199

Line width

200

- c: str or tuple, default "red"

201

Color specification

202

- alpha: float, default 1

203

Transparency value

204

"""

205

def __init__(self, p0, p1, spacing=0.1, lw=2, c="red", alpha=1): ...

206

207

class Spline:

208

"""

209

Create a smooth spline curve through points.

210

211

Parameters:

212

- points: array-like

213

Control points for spline

214

- s: float, default 0

215

Smoothing factor

216

- degree: int, default 3

217

Spline degree

218

- res: int, default None

219

Output resolution

220

- closed: bool, default False

221

Create closed curve

222

- c: str or tuple, default "blue"

223

Color specification

224

- alpha: float, default 1

225

Transparency value

226

"""

227

def __init__(self, points, s=0, degree=3, res=None, closed=False, c="blue", alpha=1): ...

228

229

class Arc:

230

"""

231

Create a circular arc.

232

233

Parameters:

234

- center: tuple, default (0, 0, 0)

235

Arc center position

236

- point1: tuple

237

First point on arc

238

- point2: tuple

239

Second point on arc

240

- normal: tuple, optional

241

Normal vector to arc plane

242

- res: int, default 50

243

Arc resolution

244

- c: str or tuple, default "red"

245

Color specification

246

- alpha: float, default 1

247

Transparency value

248

"""

249

def __init__(self, center=(0, 0, 0), point1=None, point2=None, normal=None, res=50, c="red", alpha=1): ...

250

```

251

252

### Text and Annotations

253

254

Text rendering capabilities for labels, titles, and annotations in 3D space.

255

256

```python { .api }

257

class Text3D:

258

"""

259

Create 3D text objects.

260

261

Parameters:

262

- txt: str

263

Text string to render

264

- pos: tuple, default (0, 0, 0)

265

Text position coordinates

266

- s: float, default 1

267

Text scale/size

268

- font: str, default ""

269

Font family name

270

- hspacing: float, default 1.15

271

Horizontal character spacing

272

- vspacing: float, default 2.15

273

Vertical line spacing

274

- depth: float, default 0

275

Text extrusion depth (0 for flat)

276

- italic: bool, default False

277

Use italic styling

278

- justify: str, default "bottom-left"

279

Text justification

280

- c: str or tuple, default "black"

281

Color specification

282

- alpha: float, default 1

283

Transparency value

284

"""

285

def __init__(

286

self,

287

txt,

288

pos=(0, 0, 0),

289

s=1,

290

font="",

291

hspacing=1.15,

292

vspacing=2.15,

293

depth=0,

294

italic=False,

295

justify="bottom-left",

296

c="black",

297

alpha=1

298

): ...

299

300

class Text2D:

301

"""

302

Create 2D text overlays.

303

304

Parameters:

305

- txt: str

306

Text string to render

307

- pos: tuple, default (0, 0)

308

Screen position (0-1 normalized coordinates)

309

- s: float, default 1

310

Text size

311

- font: str, default ""

312

Font family name

313

- c: str or tuple, default "black"

314

Color specification

315

- alpha: float, default 1

316

Transparency value

317

"""

318

def __init__(self, txt, pos=(0, 0), s=1, font="", c="black", alpha=1): ...

319

320

class Caption:

321

"""

322

Create caption annotations attached to 3D objects.

323

324

Parameters:

325

- obj: vedo object

326

Object to attach caption to

327

- txt: str

328

Caption text

329

- point: tuple, optional

330

Specific attachment point

331

- size: tuple, default (0.2, 0.05)

332

Caption box size

333

- padding: int, default 5

334

Text padding

335

- font: str, default ""

336

Font family name

337

- c: str or tuple, default "black"

338

Text color

339

- alpha: float, default 1

340

Transparency value

341

"""

342

def __init__(self, obj, txt="", point=None, size=(0.2, 0.05), padding=5, font="", c="black", alpha=1): ...

343

```

344

345

### 2D Shapes and Polygons

346

347

Flat geometric shapes and polygon creation tools.

348

349

```python { .api }

350

class Circle:

351

"""

352

Create a circular shape.

353

354

Parameters:

355

- pos: tuple, default (0, 0, 0)

356

Center position coordinates

357

- r: float, default 1

358

Circle radius

359

- res: int, default 24

360

Resolution (number of points)

361

- c: str or tuple, default "gray"

362

Color specification

363

- alpha: float, default 1

364

Transparency value

365

"""

366

def __init__(self, pos=(0, 0, 0), r=1, res=24, c="gray", alpha=1): ...

367

368

class Rectangle:

369

"""

370

Create a rectangular shape.

371

372

Parameters:

373

- p1: tuple, default (0, 0)

374

First corner coordinates

375

- p2: tuple, default (1, 1)

376

Opposite corner coordinates

377

- c: str or tuple, default "gray"

378

Color specification

379

- alpha: float, default 1

380

Transparency value

381

"""

382

def __init__(self, p1=(0, 0), p2=(1, 1), c="gray", alpha=1): ...

383

384

class Polygon:

385

"""

386

Create a polygon from vertices.

387

388

Parameters:

389

- vertices: array-like

390

List of vertex coordinates

391

- c: str or tuple, default "gold"

392

Color specification

393

- alpha: float, default 1

394

Transparency value

395

"""

396

def __init__(self, vertices, c="gold", alpha=1): ...

397

398

class Star:

399

"""

400

Create a star shape.

401

402

Parameters:

403

- pos: tuple, default (0, 0, 0)

404

Center position coordinates

405

- n: int, default 5

406

Number of star points

407

- r1: float, default 1

408

Outer radius

409

- r2: float, default 0.5

410

Inner radius

411

- c: str or tuple, default "blue"

412

Color specification

413

- alpha: float, default 1

414

Transparency value

415

"""

416

def __init__(self, pos=(0, 0, 0), n=5, r1=1, r2=0.5, c="blue", alpha=1): ...

417

```

418

419

### Arrows and Directional Indicators

420

421

Arrow objects for indicating directions, vectors, and flows.

422

423

```python { .api }

424

class Arrow:

425

"""

426

Create a 3D arrow object.

427

428

Parameters:

429

- startPoint: tuple, default (0, 0, 0)

430

Arrow starting position

431

- endPoint: tuple, default (1, 0, 0)

432

Arrow ending position

433

- s: float, default None

434

Arrow shaft scale

435

- c: str or tuple, default "red"

436

Color specification

437

- alpha: float, default 1

438

Transparency value

439

"""

440

def __init__(self, startPoint=(0, 0, 0), endPoint=(1, 0, 0), s=None, c="red", alpha=1): ...

441

442

class Arrows:

443

"""

444

Create multiple arrows from arrays of start/end points.

445

446

Parameters:

447

- startPoints: array-like

448

Array of starting positions

449

- endPoints: array-like

450

Array of ending positions

451

- s: float, default None

452

Arrow scale factor

453

- c: str or tuple, default "red"

454

Color specification

455

- alpha: float, default 1

456

Transparency value

457

"""

458

def __init__(self, startPoints, endPoints, s=None, c="red", alpha=1): ...

459

460

class Arrow2D:

461

"""

462

Create 2D arrow graphics.

463

464

Parameters:

465

- startPoint: tuple

466

Arrow starting position (2D)

467

- endPoint: tuple

468

Arrow ending position (2D)

469

- c: str or tuple, default "red"

470

Color specification

471

- alpha: float, default 1

472

Transparency value

473

"""

474

def __init__(self, startPoint, endPoint, c="red", alpha=1): ...

475

```

476

477

### Specialized Shapes

478

479

Advanced shapes for specific visualization purposes.

480

481

```python { .api }

482

class Tube:

483

"""

484

Create a tube along a path.

485

486

Parameters:

487

- line: Line object or array-like

488

Path to create tube along

489

- r: float, default 1

490

Tube radius

491

- res: int, default 12

492

Cross-sectional resolution

493

- c: str or tuple, default "red"

494

Color specification

495

- alpha: float, default 1

496

Transparency value

497

"""

498

def __init__(self, line, r=1, res=12, c="red", alpha=1): ...

499

500

class Spring:

501

"""

502

Create a spring/helix shape.

503

504

Parameters:

505

- startPoint: tuple, default (0, 0, 0)

506

Spring starting position

507

- endPoint: tuple, default (1, 0, 0)

508

Spring ending position

509

- coils: int, default 20

510

Number of coil turns

511

- r1: float, default 0.1

512

Spring radius

513

- r2: float, default None

514

Wire thickness radius

515

- c: str or tuple, default "blue"

516

Color specification

517

- alpha: float, default 1

518

Transparency value

519

"""

520

def __init__(self, startPoint=(0, 0, 0), endPoint=(1, 0, 0), coils=20, r1=0.1, r2=None, c="blue", alpha=1): ...

521

522

class Ribbon:

523

"""

524

Create a ribbon surface along a path.

525

526

Parameters:

527

- line: Line object or array-like

528

Path for ribbon centerline

529

- width: float, default 1

530

Ribbon width

531

- c: str or tuple, default "red"

532

Color specification

533

- alpha: float, default 1

534

Transparency value

535

"""

536

def __init__(self, line, width=1, c="red", alpha=1): ...

537

```

538

539

## Usage Examples

540

541

```python

542

import vedo

543

import numpy as np

544

545

# Create basic geometric shapes

546

sphere = vedo.Sphere(pos=(0, 0, 0), r=1.5, c='red')

547

box = vedo.Box(pos=(3, 0, 0), length=2, width=1, height=1, c='blue')

548

cylinder = vedo.Cylinder(pos=(0, 3, 0), r=0.8, height=2, c='green')

549

550

# Create complex curves

551

points = np.array([[0, 0, 0], [1, 1, 2], [2, 0, 3], [3, 1, 1]])

552

spline = vedo.Spline(points, closed=False, c='purple')

553

line = vedo.Line(points, lw=3, c='orange')

554

555

# Add text annotations

556

title = vedo.Text3D("3D Shapes Demo", pos=(0, -2, 2), s=0.5, c='black')

557

caption = vedo.Caption(sphere, "Red Sphere", size=(0.3, 0.1))

558

559

# Create arrows showing directions

560

arrow = vedo.Arrow((0, 0, 3), (2, 0, 3), c='yellow')

561

562

# Assemble and visualize

563

vedo.show(sphere, box, cylinder, spline, line, title, caption, arrow,

564

title="Shape Generation Examples", axes=True, bg='lightblue')

565

566

# Create more complex compositions

567

stars = [vedo.Star(pos=(i*2, j*2, 0), n=5+i, c=f'C{i+j}')

568

for i in range(3) for j in range(3)]

569

570

tube_path = vedo.Line([[0, 0, 0], [2, 2, 1], [4, 0, 2], [6, 2, 3]])

571

tube = vedo.Tube(tube_path, r=0.2, c='cyan')

572

573

vedo.show(stars + [tube], title="Advanced Shapes")

574

```