This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: Howto make a cross prod with gsl ?
- To: jmax dot redonnet at meca dot insa-tlse dot fr
- Subject: Re: Howto make a cross prod with gsl ?
- From: Brian Gough <bjg at network-theory dot co dot uk>
- Date: Thu, 6 Sep 2001 14:36:49 +0100 (BST)
- Cc: gsl-discuss at sourceware dot cygnus dot com
- References: <01090611384100.00456@lgmt-fab5.ups-tlse.fr>
Jean-Max Redonnet writes:
> I'm a new user of gsl I will try to use for differential geometry
> computations. Maybe I'm wrong, but I've not found a prebuilt
> function to perform cross product between vectors... ...so I've
> write one : This works fine, but I wonder if there is a best way to
> do that.
Hi,
For small vectors it will be faster to keep the components on the
stack as an ordinary array, rather than using malloc to create a
gsl_vector object.
If you need to pass the array to a gsl_linalg function you can use the
gsl_vector_view_array() function to create a temporary view.
e.g. This is how I would do it,
#define X 0
#define Y 1
#define Z 2
int main () {
double p[3] = {1, 0, 0}, q[3] = {0, 1, 0}, r[3] ;
cross(p, q, r);
}
void cross (const double * a, const double * b, double * v)
{
v[X] = a[Y] * b[Z] - a[Z] * b[Y];
....
}
regards
Brian