Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
nr-3dutils.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * 3D utils.
4 *
5 * Authors:
6 * Jean-Rene Reinhard <jr@komite.net>
7 *
8 * Copyright (C) 2007 authors
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include <glib.h>
14
15#include "display/nr-3dutils.h"
16#include <cmath>
17#include <2geom/point.h>
18#include <2geom/affine.h>
19
20namespace NR {
21
22void convert_coord(gdouble &x, gdouble &y, gdouble &z, Geom::Affine const &trans) {
23 Geom::Point p = Geom::Point(x, y);
24 p *= trans;
25 x = p[Geom::X];
26 y = p[Geom::Y];
27 z *= trans[0];
28}
29
30gdouble norm(const Fvector &v) {
31 return sqrt(v[X_3D]*v[X_3D] + v[Y_3D]*v[Y_3D] + v[Z_3D]*v[Z_3D]);
32}
33
35 gdouble nv = norm(v);
36 //TODO test nv == 0
37 for (int j = 0; j < 3; j++) {
38 v[j] /= nv;
39 }
40}
41
42gdouble scalar_product(const Fvector &a, const Fvector &b) {
43 return a[X_3D] * b[X_3D] +
44 a[Y_3D] * b[Y_3D] +
45 a[Z_3D] * b[Z_3D];
46}
47
48void normalized_sum(Fvector &r, const Fvector &a, const Fvector &b) {
49 r[X_3D] = a[X_3D] + b[X_3D];
50 r[Y_3D] = a[Y_3D] + b[Y_3D];
51 r[Z_3D] = a[Z_3D] + b[Z_3D];
53}
54
55}/* namespace NR */
56
57/*
58 Local Variables:
59 mode:c++
60 c-file-style:"stroustrup"
61 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
62 indent-tabs-mode:nil
63 fill-column:99
64 End:
65*/
66// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Cartesian point / 2D vector and related operations.
3x3 affine transformation matrix.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Two-dimensional point that doubles as a vector.
Definition point.h:66
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
void normalize_vector(Fvector &v)
Normalizes a vector.
gdouble scalar_product(const Fvector &a, const Fvector &b)
Computes the scalar product between two Fvectors.
gdouble norm(const Fvector &v)
returns the euclidean norm of the vector v
void normalized_sum(Fvector &r, const Fvector &a, const Fvector &b)
Computes the normalized sum of two Fvectors.
void convert_coord(gdouble &x, gdouble &y, gdouble &z, Geom::Affine const &trans)
a type of 3 gdouble components vectors
Definition nr-3dutils.h:29