GNU TeXmacsUser manualReferenceAboutEnglish
The algebra library and three dimensional objects

1.The algebra library

Graphics/Mathematics/

is a small header-only library of generic mathematical containers. Only matrices and polynomials are used by the rest of TeXmacs; the other classes are an experiment in generic numerical programming, exercised only by the self test test_math (

test_math.cpp

), which is called from texmacs_entrypoint only when ENABLE_TESTS is defined in

Texmacs/Texmacs/texmacs.cpp

(it is commented out).

1.1.Matrices

matrix<T> (

matrix.hpp

) is a concrete reference counted structure holding NR (m) rows and NC (m) columns in row major order; m (i, j) accesses an entry. The constructor matrix<T> (c, rows, cols) creates a matrix with c on the diagonal and zeros elsewhere, so matrix<double> (1.0, 3, 3) is the identity. The operations are:

Matrices are used by the linear_2D and affine_2D frames (see points, frames, curves and grids), by the glyph transformations of

Graphics/Bitmap_fonts/glyph_transforms.cpp

, by the (tuple "linear" …) transformations of gr-transform and the three dimensional graphics in

Typeset/Concat/concat_graphics.cpp

, and by the (unused) least squares Bezier fitting of

Graphics/Types/curve_extras.cpp

.

1.2.Polynomials and vectors

polynomial<T> (

polynomial.hpp

) stores its coefficients by increasing degree. p (x) evaluates it with Horner's scheme and p (x, k) evaluates its \(k\)-th derivative; there are +, -, *, derive and products with scalars and arrays. The spline curves of

Graphics/Types/curve.cpp

represent each basis function piece as a polynomial<double> (dpol), and each piece of the curve as a vector of such polynomials (dpols), one per coordinate.

vector<T> (

vector.hpp

) is a fixed size vector with componentwise arithmetic, elementary functions, scalar operations, square_norm, norm and derive. Note that the geometric point type is not a vector but an array<double>.

1.3.Experimental classes

ball<C>

(

ball.hpp

) Ball (interval) arithmetic: a center and a radius, with arithmetic and elementary functions which enclose the exact result.

function<F,T>

(

function.hpp

,

function_extra.hpp

) Abstract functions which can be evaluated at a point or on a ball, built from constants, coordinates, arithmetic and elementary functions, piecewise definitions (pw_function), vectors of functions and polynomials.

Operators and properties

(

operators.hpp

,

properties.hpp

) Operator classes such as add_op or neg_op, with an op method and a diff method for the derivative, and traits classes giving the scalar, norm and product types of a type. The operator classes are also used by the raster pictures (

Graphics/Pictures/raster_operators.hpp

).

Symbolic trees

(

math_tree.hpp

,

math_tree.cpp

) Arithmetic on trees (add, mul, sqrt, …), which lets the generic code run on symbolic values, and as_math_string to print them.

2.Three dimensional objects

2.1.Markup

The experimental tags object-3d, triangle-3d, transform-3d and light-3d describe a scene made of colored triangles, which is drawn inside a graphics. They are listed among the graphical primitives and declared in

Data/Drd/drd_std.cpp

:

triangle-3d

Three points with three coordinates and a color.

object-3d

A list of triangle-3ds.

transform-3d

An object and a \(4 \times 4\) matrix (a tuple of row tuples) acting on homogeneous coordinates.

light-3d

An object and a light, which is either (light-diffuse point shadow-color light-color) or (light-specular point point color). A light position with four coordinates is taken in homogeneous coordinates.

concater_rep::typeset_graphics_3d (

concat_graphics.cpp

) evaluates the tag, converts it with as_spacial and composes the result with a \(4 \times 4\) matrix built from the frame env->fr of the picture and the variable gr-transformation; the \(z\) coordinate is kept for depth sorting. Invalid input gives the error "bad spacial object". The result is a spacial_box (

Typeset/Boxes/Graphics/graphics_boxes.cpp

), which draws itself by renderer_rep::draw_spacial.

2.2.Spacial objects

A spacial (

Graphics/Spacial/spacial.hpp

) is an abstract handle with the methods get_extents, draw (renderer), transform (matrix) and enlighten (light). There are three implementations:

triangulated (ts, cs)

(

triangulated.cpp

) An array of triangles with one color each. Before drawing, the triangles are sorted by increasing mean \(z\) coordinate and drawn in that order (a painter's algorithm, without splitting of intersecting triangles); each is drawn with renderer_rep::draw_triangle. transform applies projective_apply to all vertices; enlighten recomputes the colors: a diffuse light mixes the shadow and light colors according to the angle between the normal of the triangle and the direction of the light, a specular light adds a highlight with an eighth power falloff; the computations use true_color and source_over (see colors).

transformed (obj, m), enlightened (obj, light)

(

transformed.cpp

,

enlightened.cpp

) Lazy wrappers which apply the transformation or the light on first use.

The renderers do not know about three dimensional objects: the generic renderer_rep::draw_spacial just calls obj->draw, which ends up in ordinary filled triangles.

3.Pitfalls

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".