# wgeom

Write geometry function to file

This page describes the legacy workflow. New features might not be compatible with the legacy workflow.

## Syntax

``fid = wgeom(dl,filename)``

## Description

example

````fid = wgeom(dl,filename)` writes a geometry function, specified by the geometry matrix `dl`, to a file with the name `filename.m`. For information about the geometry file format, see Parametrized Function for 2-D Geometry Creation.```

## Examples

collapse all

Create a 2-D geometry in the PDE Modeler app, export it to the MATLAB® workspace, and then write it to a file.

Start the PDE Modeler app and draw a unit circle and a unit square.

```pdecirc(0,0,1) pderect([0 1 0 1])```

Enter `C1-SQ1` in the Set formula field.

Export the geometry description matrix, set formula, and name-space matrix to the MATLAB workspace by selecting the Export Geometry Description option from the Draw menu.

Decompose the exported geometry into minimal regions. The result is one minimal region with five edge segments: three circle edge segments and two line edge segments.

`dl = decsg(gd,sf,ns)`
```dl = 2.0000 2.0000 1.0000 1.0000 1.0000 0 0 -1.0000 0.0000 0.0000 1.0000 0 0.0000 1.0000 -1.0000 0 1.0000 -0.0000 -1.0000 1.0000 0 0 -1.0000 0 -0.0000 0 0 1.0000 1.0000 1.0000 1.0000 1.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.0000 1.0000 1.0000```

Write the resulting geometry to a file. Name the file `geometry.m`.

`fid = wgeom(dl,"geometry");`

## Input Arguments

collapse all

Decomposed geometry matrix, specified as a matrix of double-precision numbers. It contains a representation of the decomposed geometry in terms of disjoint minimal regions constructed by the `decsg` algorithm. Each edge segment of the minimal regions corresponds to a column in `dl`. Edge segments between minimal regions are border segments. Outer boundaries are boundary segments. In each column, the second and third rows contain the starting and ending x-coordinates. The fourth and fifth rows contain the corresponding y-coordinates. The sixth and seventh rows contain left and right minimal region labels with respect to the direction induced by the start and end points (counterclockwise direction on circle and ellipse segments). There are three types of possible edge segments in a minimal region:

• For circle edge segments, the first row is `1`. The eighth and ninth rows contain the coordinates of the center of the circle. The 10th row contains the radius.

• For line edge segments, the first row is `2`.

• For ellipse edge segments, the first row is `4`. The eighth and ninth rows contain the coordinates of the center of the ellipse. The 10th and 11th rows contain the semiaxes of the ellipse. The 12th row contains the rotational angle of the ellipse.

All shapes in a decomposed geometry matrix have the same number of rows. Rows that are not required for a particular shape are filled with zeros.

Row number Circle edge segment Line edge segment Ellipse edge segment
1124
2starting x-coordinatestarting x-coordinatestarting x-coordinate
3ending x-coordinateending x-coordinateending x-coordinate
4starting y-coordinatestarting y-coordinatestarting y-coordinate
5ending y-coordinateending y-coordinateending y-coordinate
6left minimal region labelleft minimal region labelleft minimal region label
7right minimal region labelright minimal region labelright minimal region label
8x-coordinate of the center x-coordinate of the center
9y-coordinate of the center y-coordinate of the center
10radius of the circle x-semiaxis before rotation
11  y-semiaxis before rotation
12

Angle in radians between x-axis and first semiaxis

Data Types: `double`

Geometry file name, specified as a string or a character vector.

Data Types: `char` | `string`

## Output Arguments

collapse all

File identifier, returned as an integer. If `wgeom` cannot write the file, `fid` is `-1`. For more information about file identifiers, see `fopen`.

## Version History

Introduced before R2006a