The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
DistPtLine.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file DistPtLine.c
5 
6  \version V1.5
7  \date 20.07.15
8  \brief General maths/stats/vector functions
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1996-2015
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45 **************************************************************************
46 
47  Revision History:
48  =================
49 - V1.0 29.01.96 Original By: ACRM
50 - V1.1 18.06.96 Added vector routines
51 - V1.2 06.10.98 Added VecAdd3()
52 - V1.3 07.07.14 Use bl prefix for functions By: CTP
53 - V1.4 20.07.15 Renamed from blDistPtVect()
54 
55 *************************************************************************/
56 /* Doxygen
57  -------
58  #GROUP Maths
59  #SUBGROUP Geometry
60  #FUNCTION blDistPtLine()
61  Calculate the distance from a point to a line vector described by two
62  vector end points. See also blPointLineDistance()
63 */
64 /************************************************************************/
65 /* Includes
66 */
67 #include <math.h>
68 #include "MathType.h"
69 #include "MathUtil.h"
70 
71 /************************************************************************/
72 /* Defines and macros
73 */
74 
75 /************************************************************************/
76 /* Globals
77 */
78 
79 /************************************************************************/
80 /* Prototypes
81 */
82 
83 /************************************************************************/
84 /*>REAL blDistPtLine(VEC3F Point, VEC3F End1, VEC3F End2)
85  ------------------------------------------------------
86 *//**
87 
88  \param[in] Point The coordinates of a point
89  \param[in] End1 Coordinates of one end of vector
90  \param[in] End2 Coordinates of other end of vector
91  \return The distance from pt to line
92 
93  Calculate the distance from a point to a line described by two
94  vector end points
95 
96 - 18.06.96 Original By: ACRM
97 - 07.07.14 Use bl prefix for functions By: CTP
98 - 20.07.15 Renamed from blDistPtVect() By: ACRM
99 */
100 REAL blDistPtLine(VEC3F Point, VEC3F End1, VEC3F End2)
101 {
102  VEC3F Vec,
103  UVec,
104  PQVec,
105  PRVec;
106  REAL len;
107 
108  /* Find the vector from End1 to End2 */
109  blVecSub3(&Vec, End2, End1);
110 
111  /* Find the length of this vector */
112  len = blVecLen3(Vec);
113 
114  /* Now calculate the unit vector */
115  UVec.x = Vec.x / len;
116  UVec.y = Vec.y / len;
117  UVec.z = Vec.z / len;
118 
119  /* Calculate the vector from the point to an arbitrary point on the
120  line (we'll choose End1)
121  */
122  PQVec.x = End1.x - Point.x;
123  PQVec.y = End1.y - Point.y;
124  PQVec.z = End1.z - Point.z;
125 
126  /* PRVect is the cross product of PQVect with the unit vector */
127  blCrossProd3(&PRVec, PQVec, UVec);
128 
129  /* The length we want is the length of this vector */
130  return(blVecLen3(PRVec));
131 }
REAL x
Definition: MathType.h:70
void blCrossProd3(VEC3F *Out, VEC3F In1, VEC3F In2)
Definition: CrossProd3.c:94
REAL blDistPtLine(VEC3F Point, VEC3F End1, VEC3F End2)
Definition: DistPtLine.c:100
Definition: MathType.h:69
double REAL
Definition: MathType.h:67
void blVecSub3(VEC3F *Out, VEC3F In1, VEC3F In2)
Definition: VecSub3.c:94
Prototypes, etc. for maths utility routines.
Type definitions for maths.
REAL z
Definition: MathType.h:70
REAL y
Definition: MathType.h:70
REAL blVecLen3(VEC3F Vec)
Definition: VecLen3.c:94