From 14e4d4697b4b161277f03c2d82b14ef2619a211e Mon Sep 17 00:00:00 2001 From: Jean-baptiste Silvy Date: Mon, 31 Mar 2008 12:06:32 +0000 Subject: [PATCH] Add some geometric functions. --- scilab/modules/graphics/includes/math_graphics.h | 12 +++++++++++ scilab/modules/graphics/src/c/math_graphics.c | 25 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/scilab/modules/graphics/includes/math_graphics.h b/scilab/modules/graphics/includes/math_graphics.h index 688296c..8935afe 100644 --- a/scilab/modules/graphics/includes/math_graphics.h +++ b/scilab/modules/graphics/includes/math_graphics.h @@ -183,6 +183,18 @@ void crossProduct( const double v1[3], const double v2[3], double res[3] ) ; #define NORM_3D(v) ( sqrt( SQUARE_NORM_3D(v) ) ) /** + * substraction of two vector + * @param res result of v1 - v2 + */ +void vectSubstract3D( double v1[3], double v2[3], double res[3]); + +/** + * Multiply a vector by a scalar + * @param res scalar.v + */ +void scalarMult3D( double v[3], double scalar, double res[3]); + +/** * Normalize a 3D vector */ void normalize3D( double vect[3] ) ; diff --git a/scilab/modules/graphics/src/c/math_graphics.c b/scilab/modules/graphics/src/c/math_graphics.c index 84e8226..1c9ae26 100644 --- a/scilab/modules/graphics/src/c/math_graphics.c +++ b/scilab/modules/graphics/src/c/math_graphics.c @@ -155,9 +155,28 @@ void iNormalize2d( int vect[2] ) /*----------------------------------------------------------------------------*/ void crossProduct( const double v1[3], const double v2[3], double res[3] ) { - res[0] = v1[1] * v2[2] - v1[2] * v2[1] ; - res[1] = v1[2] * v2[0] - v1[0] * v2[2] ; - res[2] = v1[0] * v2[1] - v1[1] * v2[0] ; + /* save data to be able to use v1 o v2 as res */ + double v10 = v1[0]; + double v20 = v2[0]; + double v11 = v1[1]; + double v21 = v2[1]; + res[0] = v11 * v2[2] - v1[2] * v21 ; + res[1] = v1[2] * v20 - v10 * v2[2] ; + res[2] = v10 * v21 - v11 * v20 ; +} +/*----------------------------------------------------------------------------*/ +void vectSubstract3D( double v1[3], double v2[3], double res[3]) +{ + res[0] = v1[0] - v2[0]; + res[1] = v1[1] - v2[1]; + res[2] = v1[2] - v2[2]; +} +/*----------------------------------------------------------------------------*/ +void scalarMult3D( double v[3], double scalar, double res[3]) +{ + res[0] = scalar * v[0]; + res[1] = scalar * v[1]; + res[2] = scalar * v[2]; } /*----------------------------------------------------------------------------*/ void normalize3D( double vect[3] ) -- 1.7.9.5