1 // Boost.Geometry
2 // QuickBook Example
3
4 // Copyright (c) 2020, Aditya Mohan
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 //[cross_product
11 //` Calculate the cross product of two points
12
13
14 #include <iostream>
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/arithmetic/cross_product.hpp>
17
18 namespace bg = boost::geometry; /*< Convenient namespace alias >*/
19
main()20 int main()
21 {
22 //Example 1 2D Vector
23
24 bg::model::point<double, 2, bg::cs::cartesian> p1(7.0, 2.0);
25 bg::model::point<double, 2, bg::cs::cartesian> p2(4.0, 5.0);
26
27 bg::model::point<double, 2, bg::cs::cartesian> r1;
28
29 r1 = bg::cross_product(p1,p2);
30
31 std::cout << "Cross Product 1: "<< r1.get<0>() << std::endl; //Note that the second point (r1.get<1>) would be undefined in this case
32
33 //Example 2 - 3D Vector
34
35 bg::model::point<double, 3, bg::cs::cartesian> p3(4.0, 6.0, 5.0);
36 bg::model::point<double, 3, bg::cs::cartesian> p4(7.0, 2.0, 3.0);
37
38 bg::model::point<double, 3, bg::cs::cartesian> r2;
39
40 r2 = bg::cross_product(p3,p4);
41
42 std::cout << "Cross Product 2: ("<< r2.get<0>() <<","<< r2.get<1>() <<","<< r2.get<2>() << ")"<< std::endl;
43
44 return 0;
45 }
46
47 //]
48
49 //[cross_product_output
50 /*`
51 Output:
52 [pre
53 Cross Product 1: 27
54 Cross Product 2: (8,23,-34)
55 ]
56 */
57 //]
58