/** * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. * The Original Code is: some of this file. * * ***** END GPL LICENSE BLOCK ***** * */ #include #include #include #include #include "BLI_math.h" //******************************* Interpolation *******************************/ void interp_v2_v2v2(float *target, float *a, float *b, float t) { float s = 1.0f-t; target[0]= s*a[0] + t*b[0]; target[1]= s*a[1] + t*b[1]; } /* weight 3 2D vectors, * 'w' must be unit length but is not a vector, just 3 weights */ void interp_v2_v2v2v2(float p[2], float v1[2], float v2[2], float v3[2], float w[3]) { p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2]; p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2]; } void interp_v3_v3v3(float *target, float *a, float *b, float t) { float s = 1.0f-t; target[0]= s*a[0] + t*b[0]; target[1]= s*a[1] + t*b[1]; target[2]= s*a[2] + t*b[2]; } /* weight 3 vectors, * 'w' must be unit length but is not a vector, just 3 weights */ void interp_v3_v3v3v3(float p[3], float v1[3], float v2[3], float v3[3], float w[3]) { p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2]; p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2]; p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2]; } /* weight 3 vectors, * 'w' must be unit length but is not a vector, just 3 weights */ void interp_v3_v3v3v3v3(float p[3], float v1[3], float v2[3], float v3[3], float v4[3], float w[4]) { p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2] + v4[0]*w[3]; p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2] + v4[1]*w[3]; p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2] + v4[2]*w[3]; } void mid_v3_v3v3(float *v, float *v1, float *v2) { v[0]= 0.5f*(v1[0] + v2[0]); v[1]= 0.5f*(v1[1] + v2[1]); v[2]= 0.5f*(v1[2] + v2[2]); } /********************************* Comparison ********************************/ int is_zero_v3(float *v) { return (v[0] == 0 && v[1] == 0 && v[2] == 0); } int equals_v3v3(float *v1, float *v2) { return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2])); } int compare_v3v3(float *v1, float *v2, float limit) { if(fabs(v1[0]-v2[0])vec[0]) min[0]= vec[0]; if(min[1]>vec[1]) min[1]= vec[1]; if(min[2]>vec[2]) min[2]= vec[2]; if(max[0]