# GfsSurface

### From Gerris

Revision as of 06:59, 23 April 2007Popinet (Talk | contribs) ← Previous diff |
Current revisionGeordieMcBain (Talk | contribs) (grammar) |
||

Line 7: |
Line 7: | ||

which defines the surface as the set of points of coordinates <code>(x,y,z)</code> such that <code>x*x + y*y + z*z - 0.1*0.1 = 0</code> (i.e. a sphere of radius 0.1 centered on the origin). | which defines the surface as the set of points of coordinates <code>(x,y,z)</code> such that <code>x*x + y*y + z*z - 0.1*0.1 = 0</code> (i.e. a sphere of radius 0.1 centered on the origin). | ||

- | The sign of the implicit function defines the surface orientation. | + | The sign of the implicit function defines the surface orientation. The function should be [[:w:Continuous function|continuous]]. For example it is not a good idea to do |

+ | |||

+ | (x*x + y*y + z*z > 0.1*0.1 ? 1. : -1.) | ||

+ | |||

+ | instead of the definition above. | ||

Surfaces can also be defined explicitly using [http://gts.sourceforge.net/reference/gts-surfaces.html#GTS-SURFACE-WRITE GTS] files. For example: | Surfaces can also be defined explicitly using [http://gts.sourceforge.net/reference/gts-surfaces.html#GTS-SURFACE-WRITE GTS] files. For example: | ||

Line 20: |
Line 24: | ||

tx = 0.1 ty = -0.2 tz = 0.4 | tx = 0.1 ty = -0.2 tz = 0.4 | ||

sx = 2. sy = 1.5 sz = -1 | sx = 2. sy = 1.5 sz = -1 | ||

- | rx = 0.5 ry = -0.1 rz = -0.3 | + | rx = -45 ry = -5.5 rz = 25 |

- | angle = -45 | + | scale = 3. |

flip = 1 | flip = 1 | ||

twod = 1 | twod = 1 | ||

} | } | ||

- | where <code>(tx,ty,tz)</code> is a translation vector and <code>(sx,sy,sz)</code> is a scaling vector. The vector <code>(rx,ry,rz)</code> defines a rotation axis and <code>angle</code> the associated rotation angle (in degrees). Note that the translation is always performed after rotation and scaling. | + | where <code>(tx,ty,tz)</code> is a translation vector, <code>(sx,sy,sz)</code> is a scaling vector and <code>(rx,ry,rz)</code> is a rotation vector (angles in degrees around each principal direction). Note that the translation is always performed after rotation and scaling. |

+ | |||

+ | If the <code>scale</code> parameter is specified, uniform scaling is applied along the three axes. | ||

The <code>flip</code> parameter can be used to flip the surface orientation. | The <code>flip</code> parameter can be used to flip the surface orientation. | ||

Line 34: |
Line 40: | ||

Several simple implicit surfaces are pre-defined: | Several simple implicit surfaces are pre-defined: | ||

- | ;<code>ellipse(x,y,a,b)</code>: an ellipse centered on <code>(x,y)</code> and with semimajor axis <code>a</code> and semiminor axis <code>b</code>. | + | ;<code>ellipse(x,y,a,b)</code>: an ellipse (an elliptical prism in 3D) centered on <code>(x,y)</code> and with semimajor axis <code>a</code> and semiminor axis <code>b</code>. |

;<code>sphere(x,y,z,r)</code>: a sphere centered on <code>(x,y,z)</code> and of radius <code>r</code>. | ;<code>sphere(x,y,z,r)</code>: a sphere centered on <code>(x,y,z)</code> and of radius <code>r</code>. | ||

+ | |||

+ | ;<code>cube(x,y,z,h)</code>: a cube centered on <code>(x,y,z)</code> and of size <code>h</code>. | ||

+ | |||

+ | == Boolean operations == | ||

+ | |||

+ | Boolean operations between implicit surfaces can be used to create more complex objects (a technique also know as [[:w:Constructive solid geometry|Constructive Solid Geometry]]). Given two implicit surfaces A and B with associated implicit functions <code>fA</code> and <code>fB</code>, the standard boolean set operations can be constructed as: | ||

+ | |||

+ | ;Intersection: A ^ B = { <code>MAX (fA(x,y,z), fB(x,y,z))</code> } | ||

+ | ;Union: A U B = { <code>MIN (fA(x,y,z), fB(x,y,z))</code> } | ||

+ | ;Difference: A - B = { <code>MAX (fA(x,y,z), - fB(x,y,z))</code> } | ||

+ | |||

+ | Three predefined macros can be used to perform these boolean operations. For example the following will replicate the [[:w:Image:Csg tree.png|example]] of the wikipedia [[:w:Constructive solid geometry|CSG]] page | ||

+ | |||

+ | Solid ({ | ||

+ | double s = sphere (0, 0, 0, 0.25); | ||

+ | double c = cube (0,0,0,0.38); | ||

+ | double sIc = intersection (s, c); | ||

+ | |||

+ | double cylinder1 = x*x + y*y - 0.12*0.12; | ||

+ | double cylinder2 = z*z + y*y - 0.12*0.12; | ||

+ | double cylinder3 = x*x + z*z - 0.12*0.12; | ||

+ | double cylinderU = union (union (cylinder1, cylinder2), cylinder3); | ||

+ | |||

+ | return difference (sIc, cylinderU); | ||

+ | }) |

## Current revision

A GfsSurface is an oriented surface (in 3D) or an oriented curve (in 2D).

The surface can be defined implicitly using for example:

(x*x + y*y + z*z - 0.1*0.1)

which defines the surface as the set of points of coordinates `(x,y,z)`

such that `x*x + y*y + z*z - 0.1*0.1 = 0`

(i.e. a sphere of radius 0.1 centered on the origin).

The sign of the implicit function defines the surface orientation. The function should be continuous. For example it is not a good idea to do

(x*x + y*y + z*z > 0.1*0.1 ? 1. : -1.)

instead of the definition above.

Surfaces can also be defined explicitly using GTS files. For example:

sphere.gts

When using GTS surfaces in two dimensions, the oriented curve is defined as the intersection of the GTS surface with the `z = 0`

plane.

The surface definition can be followed by an optional parameter block with the following syntax:

{ tx = 0.1 ty = -0.2 tz = 0.4 sx = 2. sy = 1.5 sz = -1 rx = -45 ry = -5.5 rz = 25 scale = 3. flip = 1 twod = 1 }

where `(tx,ty,tz)`

is a translation vector, `(sx,sy,sz)`

is a scaling vector and `(rx,ry,rz)`

is a rotation vector (angles in degrees around each principal direction). Note that the translation is always performed after rotation and scaling.

If the `scale`

parameter is specified, uniform scaling is applied along the three axes.

The `flip`

parameter can be used to flip the surface orientation.

If set to one the `twod`

parameter "flattens" the surface on the `z = 0`

plane (this is used in 3D by the GfsRefineSurface object).

Several simple implicit surfaces are pre-defined:

`ellipse(x,y,a,b)`

- an ellipse (an elliptical prism in 3D) centered on
`(x,y)`

and with semimajor axis`a`

and semiminor axis`b`

.

`sphere(x,y,z,r)`

- a sphere centered on
`(x,y,z)`

and of radius`r`

.

`cube(x,y,z,h)`

- a cube centered on
`(x,y,z)`

and of size`h`

.

## Boolean operations

Boolean operations between implicit surfaces can be used to create more complex objects (a technique also know as Constructive Solid Geometry). Given two implicit surfaces A and B with associated implicit functions `fA`

and `fB`

, the standard boolean set operations can be constructed as:

- Intersection
- A ^ B = {
`MAX (fA(x,y,z), fB(x,y,z))`

} - Union
- A U B = {
`MIN (fA(x,y,z), fB(x,y,z))`

} - Difference
- A - B = {
`MAX (fA(x,y,z), - fB(x,y,z))`

}

Three predefined macros can be used to perform these boolean operations. For example the following will replicate the example of the wikipedia CSG page

Solid ({ double s = sphere (0, 0, 0, 0.25); double c = cube (0,0,0,0.38); double sIc = intersection (s, c); double cylinder1 = x*x + y*y - 0.12*0.12; double cylinder2 = z*z + y*y - 0.12*0.12; double cylinder3 = x*x + z*z - 0.12*0.12; double cylinderU = union (union (cylinder1, cylinder2), cylinder3); return difference (sIc, cylinderU); })