FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
parametric_curve_3d.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file parametric_curve_3d.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-14
7 @brief Parametric curve as the intersection of two parametric surfaces.@EOL
8 @std C++23
9 @copyright
10 @parblock
11 Copyright (c) 2024, Mitchell Jay Richling <http://www.mitchr.me/> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 DAMAGE.
29 @endparblock
30 @filedetails
31
32 This program produces an interesting visualization of an object known as the twisted cubic. In parametric form, the curve may be expressed as
33
34 @f[ f(t)=[t, t^2, t^3] @f]
35
36 Alternately the curve is also the intersection of two surfaces in @f$\mathbb{R}^3@f$:
37
38 @f[ y=f_2(x, z)=y^2 @f]
39 @f[ z=f_3(x, y)=x^3 @f]
40
41 The "typical" way to graph a surface like @f$f_2@f$ is to transform it into pseudo-parametric form. In Maple that might look like this
42
43 \verbatim
44 plot3d([u, u^2, v], u=-1..1, v=-1..1):
45 \endverbatim
46
47 We could do that with MRPTree, but it is easier to simply map the variables when we use construct_geometry_fans().
48
49 Another interesting use of MRPTree in this example is the way we have transformed each surface function into an SDF to drive up sample resolution near the
50 surface intersection. This would allow us to use a tool like Paraview to compute an approximation to the the intersection. Just in case the reader is
51 not using a tool that can extract a nice surface intersection, I have also dumped the curve out in a 3rd .VTU file.
52
53*/
54/*******************************************************************************************************************************************************.H.E.**/
55/** @cond exj */
56
57////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58#include "MR_rect_tree.hpp"
59#include "MR_cell_cplx.hpp"
60#include "MR_rt_to_cc.hpp"
61
62////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63typedef mjr::tree15b1d3rT tt1_t;
64typedef mjr::MRccT5 cc1_t;
65typedef mjr::MR_rt_to_cc<tt1_t, cc1_t> tc1_t;
66
67typedef mjr::tree15b2d1rT tt2_t;
68typedef mjr::MRccT5 cc2_t;
69typedef mjr::MR_rt_to_cc<tt2_t, cc2_t> tc2_t;
70
71////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
72tt1_t::rrpt_t twisted_cubic_crv(tt1_t::drpt_t t) {
73 return { t, t*t, t*t*t };
74}
75
76////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77tt2_t::rrpt_t twisted_cubic_srf1(tt2_t::drpt_t xzvec) {
78 tt2_t::src_t x = xzvec[0];
79 return x*x;
80}
81
82////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83tt2_t::src_t twisted_cubic_srf1_sdf(tt2_t::drpt_t xzvec) {
84 tt2_t::src_t z = xzvec[1];
85 return (twisted_cubic_srf1(xzvec)-z);
86}
87
88////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89tt2_t::rrpt_t twisted_cubic_srf2(tt2_t::drpt_t xyvec) {
90 tt2_t::src_t x = xyvec[0];
91 return x*x*x;
92}
93
94////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95tt2_t::src_t twisted_cubic_srf2_sdf(tt2_t::drpt_t xyvec) {
96 tt2_t::src_t y = xyvec[1];
97 return (twisted_cubic_srf2(xyvec)-y);
98}
99
100////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101int main() {
102 tt1_t crv_tree;
103 cc1_t crv_ccplx;
104 crv_tree.refine_grid(8, twisted_cubic_crv);
105 tc1_t::construct_geometry_fans(crv_ccplx,
106 crv_tree,
107 1,
108 {{tc1_t::val_src_spc_t::FRANGE, 0},
109 {tc1_t::val_src_spc_t::FRANGE, 1},
110 {tc1_t::val_src_spc_t::FRANGE, 2}});
111 crv_ccplx.create_named_datasets({"t", "x(t)", "y(t)", "z(t)"});
112 crv_ccplx.dump_cplx(5);
113 crv_ccplx.write_xml_vtk("parametric_curve_3d-crv.vtu", "parametric_curve_3d-crv");
114
115 tt2_t srf1_tree;
116 cc2_t srf1_ccplx;
117 srf1_tree.refine_grid(5, twisted_cubic_srf1);
118 srf1_tree.refine_leaves_recursive_cell_pred(6, twisted_cubic_srf1, [&srf1_tree](tt2_t::diti_t i) { return srf1_tree.cell_cross_sdf(i, twisted_cubic_srf2_sdf); });
119 srf1_tree.balance_tree(1, twisted_cubic_srf1);
120 tc2_t::construct_geometry_fans(srf1_ccplx,
121 srf1_tree,
122 2,
123 {{tc2_t::val_src_spc_t::FDOMAIN, 0},
124 {tc2_t::val_src_spc_t::FRANGE, 0},
125 {tc2_t::val_src_spc_t::FDOMAIN, 1}});
126 srf1_ccplx.create_named_datasets({"u", "v", "x(u,v)", "y(u,v)", "z(u,v)"});
127 srf1_ccplx.dump_cplx(5);
128 srf1_ccplx.write_xml_vtk("parametric_curve_3d-srf1.vtu", "parametric_curve_3d-srf1");
129
130 tt2_t srf2_tree;
131 cc2_t srf2_ccplx;
132 srf2_tree.refine_grid(5, twisted_cubic_srf2);
133 srf2_tree.refine_leaves_recursive_cell_pred(6, twisted_cubic_srf2, [&srf2_tree](tt2_t::diti_t i) { return srf2_tree.cell_cross_sdf(i, twisted_cubic_srf1_sdf); });
134 srf2_tree.balance_tree(1, twisted_cubic_srf2);
135 tc2_t::construct_geometry_fans(srf2_ccplx,
136 srf2_tree,
137 2,
138 {{tc2_t::val_src_spc_t::FRANGE, 0},
139 {tc2_t::val_src_spc_t::FRANGE, 1},
140 {tc2_t::val_src_spc_t::FRANGE, 2}});
141 srf2_ccplx.create_named_datasets({"u", "v", "x(u,v)", "y(u,v)", "z(u,v)"});
142 srf2_ccplx.dump_cplx(5);
143 srf2_ccplx.write_xml_vtk("parametric_curve_3d-srf2.vtu", "parametric_curve_3d-srf2");
144}
145/** @endcond */
int main()