/ concept-collection / surfacefun-interactive
Sign in
concept-collection / surfacefun-interactive
54 lines · 1.8 KBBlameHistoryRaw
1function vector_field_viewer(dom)
2%VECTOR_FIELD_VIEWER Interactive figure showing a tangent vector field on a surface.
3% VECTOR_FIELD_VIEWER(DOM) opens a figure that renders a tangent vector
4% field on the surfacemesh DOM. The arrow scale can be adjusted with a
5% slider in the figure (purely client-side; no MATLAB callback needed).
7html = fileread(fullfile('app', 'dist', 'index.html'));
8data = build_data(dom);
10fig = figure;
11gl = uigridlayout(fig, [1 1], 'Padding', [0 0 0 0], ...
12 'RowHeight', {'1x'}, 'ColumnWidth', {'1x'});
13uihtml(gl, 'HTMLSource', html, 'Data', data);
14end
16function data = build_data(dom)
17%BUILD_DATA Pack surface patches and a dense divergence-free tangent vector field.
18% Samples every collocation point across all patches. The field is the
19% stream-function field for F = xyz:
20% v = (x(y^2-z^2), y(z^2-x^2), z(x^2-y^2))
21% It is automatically tangent to the unit sphere (v·n = 0) and
22% divergence-free. The flow has 8 vortex centres at the cube vertices and
23% 6 saddle points at the cube-face centres, producing eight distinct
24% swirling regions whose index sum satisfies the Poincare-Hopf theorem.
26np = length(dom);
27px = cell(1, np);
28py = cell(1, np);
29pz = cell(1, np);
30for k = 1:np
31 px{k} = real(dom.x{k}(:).');
32 py{k} = real(dom.y{k}(:).');
33 pz{k} = real(dom.z{k}(:).');
34end
36% Collect ALL collocation points across every patch.
37all_x = horzcat(px{:});
38all_y = horzcat(py{:});
39all_z = horzcat(pz{:});
41% Stream-function vector field v = n x grad_S(xyz) on the unit sphere.
42uu = all_x .* (all_y.^2 - all_z.^2);
43vv = all_y .* (all_z.^2 - all_x.^2);
44ww = all_z .* (all_x.^2 - all_y.^2);
46data = struct();
47data.type = 'vectorfield';
48data.n = size(dom.x{1}, 1);
49data.x = px;
50data.y = py;
51data.z = pz;
52data.npatches = np;
53data.vectors = struct('x', all_x, 'y', all_y, 'z', all_z, 'u', uu, 'v', vv, 'w', ww);
54end
moveopenescclose