• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>dot_product</title>
5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../index.html" title="Chapter 1. Geometry">
8<link rel="up" href="../arithmetic.html" title="Arithmetic">
9<link rel="prev" href="divide_value.html" title="divide_value">
10<link rel="next" href="multiply_point.html" title="multiply_point">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="divide_value.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../arithmetic.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="multiply_point.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="geometry.reference.arithmetic.dot_product"></a><a class="link" href="dot_product.html" title="dot_product">dot_product</a>
28</h4></div></div></div>
29<p>
30          <a class="indexterm" name="idm45635685709936"></a>
31Computes the dot product (or scalar product) of 2 vectors (points).
32        </p>
33<h6>
34<a name="geometry.reference.arithmetic.dot_product.h0"></a>
35          <span class="phrase"><a name="geometry.reference.arithmetic.dot_product.synopsis"></a></span><a class="link" href="dot_product.html#geometry.reference.arithmetic.dot_product.synopsis">Synopsis</a>
36        </h6>
37<p>
38</p>
39<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Point1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Point2</span><span class="special">&gt;</span>
40<span class="identifier">select_coordinate_type</span><span class="special">&lt;</span><span class="identifier">Point1</span><span class="special">,</span> <span class="identifier">Point2</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">dot_product</span><span class="special">(</span><span class="identifier">Point1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">p1</span><span class="special">,</span> <span class="identifier">Point2</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">p2</span><span class="special">)</span></pre>
41<p>
42        </p>
43<h6>
44<a name="geometry.reference.arithmetic.dot_product.h1"></a>
45          <span class="phrase"><a name="geometry.reference.arithmetic.dot_product.parameters"></a></span><a class="link" href="dot_product.html#geometry.reference.arithmetic.dot_product.parameters">Parameters</a>
46        </h6>
47<div class="informaltable"><table class="table">
48<colgroup>
49<col>
50<col>
51<col>
52<col>
53</colgroup>
54<thead><tr>
55<th>
56                  <p>
57                    Type
58                  </p>
59                </th>
60<th>
61                  <p>
62                    Concept
63                  </p>
64                </th>
65<th>
66                  <p>
67                    Name
68                  </p>
69                </th>
70<th>
71                  <p>
72                    Description
73                  </p>
74                </th>
75</tr></thead>
76<tbody>
77<tr>
78<td>
79                  <p>
80                    Point1 const &amp;
81                  </p>
82                </td>
83<td>
84                  <p>
85                    Any type fulfilling a Point Concept
86                  </p>
87                </td>
88<td>
89                  <p>
90                    p1
91                  </p>
92                </td>
93<td>
94                  <p>
95                    first point
96                  </p>
97                </td>
98</tr>
99<tr>
100<td>
101                  <p>
102                    Point2 const &amp;
103                  </p>
104                </td>
105<td>
106                  <p>
107                    Any type fulfilling a Point Concept
108                  </p>
109                </td>
110<td>
111                  <p>
112                    p2
113                  </p>
114                </td>
115<td>
116                  <p>
117                    second point
118                  </p>
119                </td>
120</tr>
121</tbody>
122</table></div>
123<h6>
124<a name="geometry.reference.arithmetic.dot_product.h2"></a>
125          <span class="phrase"><a name="geometry.reference.arithmetic.dot_product.returns"></a></span><a class="link" href="dot_product.html#geometry.reference.arithmetic.dot_product.returns">Returns</a>
126        </h6>
127<p>
128          the dot product
129        </p>
130<h6>
131<a name="geometry.reference.arithmetic.dot_product.h3"></a>
132          <span class="phrase"><a name="geometry.reference.arithmetic.dot_product.header"></a></span><a class="link" href="dot_product.html#geometry.reference.arithmetic.dot_product.header">Header</a>
133        </h6>
134<p>
135          Either
136        </p>
137<p>
138          <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
139        </p>
140<p>
141          Or
142        </p>
143<p>
144          <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">arithmetic</span><span class="special">/</span><span class="identifier">dot_product</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
145        </p>
146<h6>
147<a name="geometry.reference.arithmetic.dot_product.h4"></a>
148          <span class="phrase"><a name="geometry.reference.arithmetic.dot_product.examples"></a></span><a class="link" href="dot_product.html#geometry.reference.arithmetic.dot_product.examples">Examples</a>
149        </h6>
150<p>
151          Calculate the dot product of two points
152        </p>
153<p>
154</p>
155<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
156
157<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
158<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">arithmetic</span><span class="special">/</span><span class="identifier">dot_product</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
159<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">adapted</span><span class="special">/</span><span class="identifier">boost_array</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
160
161<span class="keyword">namespace</span> <span class="identifier">bg</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">;</span> <a class="co" name="geometry.reference.arithmetic.dot_product.c0" href="dot_product.html#geometry.reference.arithmetic.dot_product.c1"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
162
163<span class="identifier">BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS</span><span class="special">(</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">)</span>
164
165
166<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
167<span class="special">{</span>
168     <span class="keyword">double</span> <span class="identifier">dp1</span><span class="special">,</span><span class="identifier">dp2</span><span class="special">,</span><span class="identifier">dp3</span><span class="special">,</span><span class="identifier">dp4</span><span class="special">;</span>
169     <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">&gt;</span> <span class="identifier">point1</span><span class="special">(</span><span class="number">1.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">,</span> <span class="number">3.0</span><span class="special">);</span>
170     <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">&gt;</span> <span class="identifier">point2</span><span class="special">(</span><span class="number">4.0</span><span class="special">,</span> <span class="number">5.0</span><span class="special">,</span> <span class="number">6.0</span><span class="special">);</span>
171
172     <span class="comment">//Example 1</span>
173     <span class="identifier">dp1</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">dot_product</span><span class="special">(</span><span class="identifier">point1</span><span class="special">,</span> <span class="identifier">point2</span><span class="special">);</span>
174
175     <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Dot Product 1: "</span><span class="special">&lt;&lt;</span> <span class="identifier">dp1</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
176
177     <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">&gt;</span> <span class="identifier">point3</span><span class="special">(</span><span class="number">3.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">);</span>
178     <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">&gt;</span> <span class="identifier">point4</span><span class="special">(</span><span class="number">4.0</span><span class="special">,</span> <span class="number">7.0</span><span class="special">);</span>
179
180     <span class="comment">//Example 2	</span>
181     <span class="identifier">dp2</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">dot_product</span><span class="special">(</span><span class="identifier">point3</span><span class="special">,</span> <span class="identifier">point4</span><span class="special">);</span>
182
183     <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Dot Product 2: "</span><span class="special">&lt;&lt;</span> <span class="identifier">dp2</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
184
185     <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">&gt;</span> <span class="identifier">a</span> <span class="special">=</span>  <span class="special">{</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">};</span>
186     <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">&gt;</span> <span class="identifier">b</span> <span class="special">=</span>  <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
187
188     <span class="comment">//Example 3</span>
189     <span class="identifier">dp3</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">dot_product</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">);</span>
190
191     <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Dot Product 3: "</span><span class="special">&lt;&lt;</span> <span class="identifier">dp3</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
192
193     <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
194
195<span class="special">}</span>
196</pre>
197<p>
198        </p>
199<div class="calloutlist"><table border="0" summary="Callout list"><tr>
200<td width="5%" valign="top" align="left"><p><a name="geometry.reference.arithmetic.dot_product.c1"></a><a href="#geometry.reference.arithmetic.dot_product.c0"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
201<td valign="top" align="left"><p>
202              Convenient namespace alias
203            </p></td>
204</tr></table></div>
205<p>
206          Output:
207        </p>
208<pre class="programlisting">Dot Product 1: 32
209Dot Product 2: 26
210Dot Product 3: 8
211</pre>
212</div>
213<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
214<td align="left"></td>
215<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
216      Wulkiewicz, Oracle and/or its affiliates<p>
217        Distributed under the Boost Software License, Version 1.0. (See accompanying
218        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
219      </p>
220</div></td>
221</tr></table>
222<hr>
223<div class="spirit-nav">
224<a accesskey="p" href="divide_value.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../arithmetic.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="multiply_point.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
225</div>
226</body>
227</html>
228