distpointline.c

Go to the documentation of this file.
00001 /*
00002     This file is part of magpar.
00003 
00004     Copyright (C) 2002-2010 Werner Scholz
00005 
00006     www:   http://www.magpar.net/
00007     email: magpar(at)magpar.net
00008 
00009     magpar is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     magpar is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with magpar; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 static char const Id[] = "$Id: distpointline.c 2962 2010-02-04 19:50:44Z scholz $\n\n";
00025 static char const Td[] = "$Today: " __FILE__ "  " __DATE__ "  "  __TIME__  " $\n\n";
00026 
00027 #include "util.h"
00028 
00029 /* Weisstein, Eric W. "Point-Line Distance--3-Dimensional." From MathWorld--A Wolfram Web Resource.
00030  * http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
00031  */
00032 int DistPointLine(PetscReal *point,PetscReal *linepoint,PetscReal *linevec,PetscReal *dist)
00033 {
00034   PetscReal x0[ND],x1[ND],x2[ND];
00035 
00036   my_dcopy(ND,point,1,x0,1);
00037   my_dcopy(ND,linepoint,1,x1,1);
00038 
00039   my_dcopy(ND,linepoint,1,x2,1);
00040   my_daxpy(ND,1.0,linevec,1,x2,1);
00041 
00042   PetscReal d01[ND],d02[ND],d12[ND];
00043 
00044   my_dcopy(ND,x1,1,d01,1);
00045   my_daxpy(ND,-1.0,x0,1,d01,1);
00046 
00047   my_dcopy(ND,x2,1,d02,1);
00048   my_daxpy(ND,-1.0,x0,1,d02,1);
00049 
00050   my_dcopy(ND,x2,1,d12,1);
00051   my_daxpy(ND,-1.0,x1,1,d12,1);
00052 
00053   PetscReal t[ND];
00054   douter(ND,d01,d02,t);
00055 
00056   PetscReal n1,n2;
00057   n1=my_dnrm2(ND,t,1);
00058   n2=my_dnrm2(ND,d12,1);
00059   if (n1<D_EPS) {
00060     *dist=0.0;
00061   }
00062   else {
00063     *dist=n1/n2;
00064   }
00065 
00066   return(0);
00067 }
00068 

magpar - Parallel Finite Element Micromagnetics Package
Copyright (C) 2002-2010 Werner Scholz