How to make a function that calculates many coefficients (>100) and reclaim them on many functions without having to return all these values?

1 view (last 30 days)
I have a surface, and I have to calculate A LOT of different coefficients for a point on this surface.
This is the function wich calculates the coeficientes on the point x=[u v] of a surface:
function the_coeficients_of_a_point_on_surface(x)
u = x(1)
v = x(2)
%% Defines surface
%Surface from Cazals article
U = [0 0 0 0 0 1 1 1 1 1];
V = [0 0 0 0 0 1 1 1 1 1];
k = 4;
l = 4;
P = [0 1/4 2/4 3/4 1; 0 1/4 2/4 3/4 4/4; 0 1/4 2/4 3/4 4/4; 0 1/4 2/4 3/4 4/4; 0 1/4 2/4 3/4 1];
P(:,:,2) = [0 0 0 0 0; 1/4 1/4 1/4 1/4 1/4; 2/4 2/4 2/4 2/4 2/4; 3/4 3/4 3/4 3/4 3/4; 1 1 1 1 1];
P(:,:,3) = [0 0 0 0 0; 0 1 -1 -1 0 ; 0 -1 1 1 0 ; 0 1 -1 1 0 ; 0 0 0 0 0];
P(:,:,4) = [1 1 1 1 1; 1 1 1 1 1 ; 1 1 1 1 1 ; 1 1 1 1 1 ; 1 1 1 1 1];
%corrects parameters
P(:,:,1) = transpose(P(:,:,1));
P(:,:,2) = transpose(P(:,:,2));
P(:,:,3) = transpose(P(:,:,3));
P(:,:,4) = transpose(P(:,:,4));
%Puts everything on homogenous coordinates
PW(:,:,1) = P(:,:,4).*P(:,:,1);
PW(:,:,2) = P(:,:,4).*P(:,:,2);
PW(:,:,3) = P(:,:,4).*P(:,:,3);
PW(:,:,4) = P(:,:,4);
%% Surface operations
%- partial derivatives of the surface (order 1 to 4)
%- Use squeeze(DS(c,d,:))' to get vector of partial derivative values
DS = derivative_order_cd_NURBS_surface(u,v,U,V,PW,k+1,l+1,5,5);
%% First fundamental form and its partial derivatives
[E,Eu,Ev,Euu,Euv,Evv,...
F,Fu,Fv,Fuu,Fuv,Fvv,...
G,Gu,Gv,Guu,Guv,Gvv] = first_fundamental_form(squeeze(DS(2,1,:))',squeeze(DS(1,2,:))',...
squeeze(DS(3,1,:))',squeeze(DS(2,2,:))',squeeze(DS(1,2,:))',...
squeeze(DS(4,1,:))',squeeze(DS(3,2,:))',squeeze(DS(2,3,:))',squeeze(DS(1,4,:))');
%% Surface normal, Rational Surface Normal (bar) and its partial derivatives
[N,barN,...
barNu,barNv,...
barNuu,barNuv,barNvv] = surface_normal(squeeze(DS(2,1,:))',squeeze(DS(1,2,:))',...
squeeze(DS(3,1,:))',squeeze(DS(2,2,:))',squeeze(DS(1,2,:))',...
squeeze(DS(4,1,:))',squeeze(DS(3,2,:))',squeeze(DS(2,3,:))',squeeze(DS(1,4,:))');
%% Second fundamental form, rational Second fundamental form (bar) and its partial derivatives
[e,bare,...
bareu,barev,bareuu,bareuv,barevv,...
f,barf,...
barfu,barfv,barfuu,barfuv,barfvv,...
g,barg,...
bargu,bargv,barguu,barguv,bargvv] = second_fundamental_form(squeeze(DS(3,1,:))',squeeze(DS(2,2,:))',squeeze(DS(1,2,:))',...
squeeze(DS(4,1,:))',squeeze(DS(3,2,:))',squeeze(DS(2,3,:))',squeeze(DS(1,4,:))',...
squeeze(DS(5,1,:))',squeeze(DS(4,2,:))',squeeze(DS(3,3,:))',squeeze(DS(2,4,:))',squeeze(DS(1,5,:))',...
N,barN,barNu,barNv,barNuu,barNuv,barNvv);
%% Principal curvatures coefficients and its partial derivatives
[A,Au,Av,Auu,Auv,Avv,...
B,barB,barBu,barBv,barBuu,barBuv,barBvv,...
C,barC,barCu,barCv,barCuu,barCuv,barCvv] = auxiliary_ABC(E,Eu,Ev,Euu,Euv,Evv,...
F,Fu,Fv,Fuu,Fuv,Fvv,...
G,Gu,Gv,Guu,Guv,Gvv,...
e,bare,bareu,barev,bareuu,bareuv,barevv,...
f,barf,barfu,barfv,barfuu,barfuv,barfvv,...
g,barg,bargu,bargv,barguu,barguv,bargvv);
%% Rational coefficients for ridges and umbilics
[Pu,Puu,Puv,Pv,Pvu,Pvv,...
Ru,Ruu,Ruv,Rv,Rvu,Rvv,...
Q,Qu,Qv] = auxiliary_PRQ(A,Au,Av,Auu,Auv,Avv,...
barB,barBu,barBv,barBuu,barBuv,barBvv,...
barC,barCu,barCv,barCuu,barCuv,barCvv);
end
I have all these coefficients and I wanted them to work like the code below on many functions:
function [y] = critical_points(x)
the_coeficients_of_a_point_on_surface(x)
%% Algorithm description
%--Generates curvature critical points system of equations
y(1) = Q.*(Pu.^2) - Ru.^2;
y(2) = Q.*(Pv.^2) - Rv.^2;
end
The reason behind this is because I'll have to use these smaller functions in a lot of other functions, and I really want these smaller functions to have only "x" as input. The smaller function doesn't work. Is there a way to define the function "the_coeficients_of_a_point_on_surface(x)" so the "critical_points(x)" function works?
I'll have lots of other smaller functions that will use all the coefficients, not only the coefficients "critical_points(x)" is using. The point is: I don't want to make "the_coeficients_of_a_point_on_surface(x)" to return ALL its coefficients. I just want to be able to calculate and use them on functions that look like "critical_points(x)"

Answers (1)

John D'Errico
John D'Errico on 14 May 2021
Return a single struct that contains all of these variables as fields.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!