• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>cross_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="cross_product_2.html" title="cross_product">
10<link rel="next" href="divide_point.html" title="divide_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="cross_product_2.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="divide_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.cross_product_2_0"></a><a class="link" href="cross_product_2_0.html" title="cross_product">cross_product</a>
28</h4></div></div></div>
29<p>
30          <a class="indexterm" name="idm45635686019616"></a>
31Computes the cross product of two vectors.
32        </p>
33<h6>
34<a name="geometry.reference.arithmetic.cross_product_2.h5"></a>
35          <span class="phrase"><a name="geometry.reference.arithmetic.cross_product_2.description0"></a></span><a class="link" href="cross_product_2_0.html#geometry.reference.arithmetic.cross_product_2.description0">Description</a>
36        </h6>
37<p>
38          All vectors should have the same dimension, 3 or 2.
39        </p>
40<h6>
41<a name="geometry.reference.arithmetic.cross_product_2.h6"></a>
42          <span class="phrase"><a name="geometry.reference.arithmetic.cross_product_2.synopsis0"></a></span><a class="link" href="cross_product_2_0.html#geometry.reference.arithmetic.cross_product_2.synopsis0">Synopsis</a>
43        </h6>
44<p>
45</p>
46<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">P</span><span class="special">&gt;</span>
47<span class="identifier">P</span> <span class="identifier">cross_product</span><span class="special">(</span><span class="identifier">P</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">p1</span><span class="special">,</span> <span class="identifier">P</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">p2</span><span class="special">)</span></pre>
48<p>
49        </p>
50<h6>
51<a name="geometry.reference.arithmetic.cross_product_2.h7"></a>
52          <span class="phrase"><a name="geometry.reference.arithmetic.cross_product_2.parameters0"></a></span><a class="link" href="cross_product_2_0.html#geometry.reference.arithmetic.cross_product_2.parameters0">Parameters</a>
53        </h6>
54<div class="informaltable"><table class="table">
55<colgroup>
56<col>
57<col>
58<col>
59<col>
60</colgroup>
61<thead><tr>
62<th>
63                  <p>
64                    Type
65                  </p>
66                </th>
67<th>
68                  <p>
69                    Concept
70                  </p>
71                </th>
72<th>
73                  <p>
74                    Name
75                  </p>
76                </th>
77<th>
78                  <p>
79                    Description
80                  </p>
81                </th>
82</tr></thead>
83<tbody>
84<tr>
85<td>
86                  <p>
87                    P const &amp;
88                  </p>
89                </td>
90<td>
91                </td>
92<td>
93                  <p>
94                    p1
95                  </p>
96                </td>
97<td>
98                  <p>
99                    first vector
100                  </p>
101                </td>
102</tr>
103<tr>
104<td>
105                  <p>
106                    P const &amp;
107                  </p>
108                </td>
109<td>
110                </td>
111<td>
112                  <p>
113                    p2
114                  </p>
115                </td>
116<td>
117                  <p>
118                    second vector
119                  </p>
120                </td>
121</tr>
122</tbody>
123</table></div>
124<h6>
125<a name="geometry.reference.arithmetic.cross_product_2.h8"></a>
126          <span class="phrase"><a name="geometry.reference.arithmetic.cross_product_2.returns0"></a></span><a class="link" href="cross_product_2_0.html#geometry.reference.arithmetic.cross_product_2.returns0">Returns</a>
127        </h6>
128<p>
129          the cross product vector
130        </p>
131<h6>
132<a name="geometry.reference.arithmetic.cross_product_2.h9"></a>
133          <span class="phrase"><a name="geometry.reference.arithmetic.cross_product_2.header0"></a></span><a class="link" href="cross_product_2_0.html#geometry.reference.arithmetic.cross_product_2.header0">Header</a>
134        </h6>
135<p>
136          <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">cross_product</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
137        </p>
138<h6>
139<a name="geometry.reference.arithmetic.cross_product_2.h10"></a>
140          <span class="phrase"><a name="geometry.reference.arithmetic.cross_product_2.examples"></a></span><a class="link" href="cross_product_2_0.html#geometry.reference.arithmetic.cross_product_2.examples">Examples</a>
141        </h6>
142<p>
143          Calculate the cross product of two points
144        </p>
145<p>
146</p>
147<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
148<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>
149<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">cross_product</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
150
151<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.cross_product_2.c0" href="cross_product_2_0.html#geometry.reference.arithmetic.cross_product_2.c1"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
152
153<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
154<span class="special">{</span>
155     <span class="comment">//Example 1 2D Vector</span>
156
157     <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">p1</span><span class="special">(</span><span class="number">7.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">);</span>
158     <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">p2</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>
159
160     <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">r1</span><span class="special">;</span>
161
162     <span class="identifier">r1</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cross_product</span><span class="special">(</span><span class="identifier">p1</span><span class="special">,</span><span class="identifier">p2</span><span class="special">);</span>
163
164     <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Cross Product 1: "</span><span class="special">&lt;&lt;</span> <span class="identifier">r1</span><span class="special">.</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;()</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>  <span class="comment">//Note that the second point (r1.get&lt;1&gt;) would be undefined in this case</span>
165
166     <span class="comment">//Example 2 - 3D Vector </span>
167
168     <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">p3</span><span class="special">(</span><span class="number">4.0</span><span class="special">,</span> <span class="number">6.0</span><span class="special">,</span> <span class="number">5.0</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">p4</span><span class="special">(</span><span class="number">7.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
171     <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">r2</span><span class="special">;</span>
172
173     <span class="identifier">r2</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cross_product</span><span class="special">(</span><span class="identifier">p3</span><span class="special">,</span><span class="identifier">p4</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">"Cross Product 2: ("</span><span class="special">&lt;&lt;</span> <span class="identifier">r2</span><span class="special">.</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;()</span> <span class="special">&lt;&lt;</span><span class="string">","</span><span class="special">&lt;&lt;</span> <span class="identifier">r2</span><span class="special">.</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;()</span> <span class="special">&lt;&lt;</span><span class="string">","</span><span class="special">&lt;&lt;</span> <span class="identifier">r2</span><span class="special">.</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">2</span><span class="special">&gt;()</span> <span class="special">&lt;&lt;</span> <span class="string">")"</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="keyword">return</span> <span class="number">0</span><span class="special">;</span>
178<span class="special">}</span>
179</pre>
180<p>
181        </p>
182<div class="calloutlist"><table border="0" summary="Callout list"><tr>
183<td width="5%" valign="top" align="left"><p><a name="geometry.reference.arithmetic.cross_product_2.c1"></a><a href="#geometry.reference.arithmetic.cross_product_2.c0"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
184<td valign="top" align="left"><p>
185              Convenient namespace alias
186            </p></td>
187</tr></table></div>
188<p>
189          Output:
190        </p>
191<pre class="programlisting">Cross Product 1: 27
192Cross Product 2: (8,23,-34)
193</pre>
194</div>
195<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
196<td align="left"></td>
197<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam
198      Wulkiewicz, Oracle and/or its affiliates<p>
199        Distributed under the Boost Software License, Version 1.0. (See accompanying
200        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>)
201      </p>
202</div></td>
203</tr></table>
204<hr>
205<div class="spirit-nav">
206<a accesskey="p" href="cross_product_2.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="divide_point.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
207</div>
208</body>
209</html>
210