Finding corresponding values from a 3d Surface

2 次查看(过去 30 天)
Hello there,
I am having trouble with finding values in a 3D-Surface I have plotted. I guess the solution to this is relatively simple, but I just don't get what to do.
I have created a 3-D surface according to 3 corresponding matrixs, as shown in the code below. This worked fairly well and I do get the exact surface I was looking for (figure 1). Next I plotted the point of my values ang_vel, ang_flex, and Fext(end) (which is 11.5295). Now here is my problem: Corresponding to this point, I would like to know, which y-value it has, when it touches the 3D-surface.
clear
clc
close all
%%EINLESEN DER KRAFTDATEN
Pfad_Programm=cd;
[num, txt]=xlsread('Participant_1_1_NE_alle Trials_MuscleOutput.xlsx',1,'B8:E2015');
daten=xlsread('Participant_1_1_NE_alle Trials_MuscleOutput.xlsx',1);
Fext=daten(8:end,3)*100; %_deltoideus_anterior_part1 in %
ang_vel=60; %Winkelgeschwindigkeit während des Versuchs
angle_flex=60; %Ellenbogenflexionswinkel während des Versuchs
torque_male_flex=[56.4 62.9 63.0 60.3 56.4;41.2 43.9 44.7 42.3 35.7;36.1 38.0 38.7 36.8 27.9;32.1 33.9 33.1 29.2 18.7;0 30.0 27.9 21.5 12.0;0 0 25.7 18.4 8.4];
torque_female_flex=[26.2 30.4 32.0 32.4 30.4;20.4 20.8 21.4 20.8 18.3;18.9 19.4 19.9 19.0 15.2;15.9 18.2 17.9 15.6 11.3;0 14.4 15.8 13.2 8.1;0 0 14.1 13.2 8.7];
vel=[0 0 0 0 0;60 60 60 60 60;120 120 120 120 120;180 180 180 180 180;240 240 240 240 240;300 300 300 300 300];
vel2=[300 300 300 300 300;240 240 240 240 240;180 180 180 180 180;120 120 120 120 120;60 60 60 60 60;0 0 0 0 0;];
ang2=[15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110];
figure (1)
surf(ang2,vel2,torque_male_flex);
title('tva surface - male elbow flexion');
xlabel('velocity')
ylabel('angle')
zlabel('torque')
hold on
plot3(angle_flex,ang_vel,Fext(end),'o');
Thanks a lot for helping!
Best regards,
Christian

回答(1 个)

Prabhan Purwar
Prabhan Purwar 2020-3-6
编辑:Prabhan Purwar 2020-3-6
Hello,
Following code may help:
clc
close all
clear
%Z=11.5295;
ang_vel=60; %Winkelgeschwindigkeit während des Versuchs
angle_flex=60; %Ellenbogenflexionswinkel während des Versuchs
X=angle_flex;
Y=ang_vel;
Z=40; %Z value to intersect
torque_male_flex=[56.4 62.9 63.0 60.3 56.4;41.2 43.9 44.7 42.3 35.7;36.1 38.0 38.7 36.8 27.9;32.1 33.9 33.1 29.2 18.7;0 30.0 27.9 21.5 12.0;0 0 25.7 18.4 8.4];
torque_female_flex=[26.2 30.4 32.0 32.4 30.4;20.4 20.8 21.4 20.8 18.3;18.9 19.4 19.9 19.0 15.2;15.9 18.2 17.9 15.6 11.3;0 14.4 15.8 13.2 8.1;0 0 14.1 13.2 8.7];
vel=[0 0 0 0 0;60 60 60 60 60;120 120 120 120 120;180 180 180 180 180;240 240 240 240 240;300 300 300 300 300];
vel2=[300 300 300 300 300;240 240 240 240 240;180 180 180 180 180;120 120 120 120 120;60 60 60 60 60;0 0 0 0 0;];
ang2=[15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110];
f=createFit(ang2, vel2, torque_male_flex);
title('tva surface - male elbow flexion');
xlabel('velocity')
ylabel('angle')
zlabel('torque')
hold on
plot3(X,Y,Z,'o','MarkerSize',10); %given point
plot3(X,-50:300,Z,'o','MarkerSize',1); %Normal to point
for i=0:0.01:300
val=f(angle_flex,i);
if (round(val,2)==Z)disp('intersection');
in=i;
end
end
plot3(angle_flex,in,Z,'o','MarkerSize',10) %Intersection point
Kindly include following function created using surface fitting.
function [fitresult, gof] = createFit(ang2, vel2, torque_male_flex)
%CREATEFIT(ANG2,VEL2,TORQUE_MALE_FLEX)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : ang2
% Y Input : vel2
% Z Output: torque_male_flex
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 06-Mar-2020 12:04:25
%% Fit: 'untitled fit 1'.
[xData, yData, zData] = prepareSurfaceData( ang2, vel2, torque_male_flex );
% Set up fittype and options.
ft = 'thinplateinterp';
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'untitled fit 1', 'torque_male_flex vs. ang2, vel2', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'ang2', 'Interpreter', 'none' );
ylabel( 'vel2', 'Interpreter', 'none' );
zlabel( 'torque_male_flex', 'Interpreter', 'none' );
grid on
Output:
Kindly set
  • X,Y and Z values
  • Value of precision in round(val,2) to get the precise coordinates for the point of intersection.
Following links may help:
  1 个评论
Christian Gärtner
Hi Prabhan Purwar,
first, thanks a lot for your answer it is deeply appreciated and already is helping me a lot.
I actually want to find another intersecting point. So you can see which point I am talking about, I modified your code, so the normal to the intersection point is pointing into the right direction.
I also switched the axis "angle" with "velocity", because this is the way I would like it to be.
Still I somehow can't get the intersection point in the direction of the normal, as in the code below, because I am unsure how to change your code. Could you please help me with that? Thanks a lot!
clc
close all
clear
%Z=11.5295;
ang_vel=60; %Winkelgeschwindigkeit während des Versuchs
angle_flex=60; %Ellenbogenflexionswinkel während des Versuchs
X=angle_flex;
Y=ang_vel;
Z=20; %Z value to intersect
torque_male_flex=[56.4 62.9 63.0 60.3 56.4;41.2 43.9 44.7 42.3 35.7;36.1 38.0 38.7 36.8 27.9;32.1 33.9 33.1 29.2 18.7;0 30.0 27.9 21.5 12.0;0 0 25.7 18.4 8.4];
torque_female_flex=[26.2 30.4 32.0 32.4 30.4;20.4 20.8 21.4 20.8 18.3;18.9 19.4 19.9 19.0 15.2;15.9 18.2 17.9 15.6 11.3;0 14.4 15.8 13.2 8.1;0 0 14.1 13.2 8.7];
vel2=[0 0 0 0 0;60 60 60 60 60;120 120 120 120 120;180 180 180 180 180;240 240 240 240 240;300 300 300 300 300];
%vel2=[300 300 300 300 300;240 240 240 240 240;180 180 180 180 180;120 120 120 120 120;60 60 60 60 60;0 0 0 0 0;];
ang2=[15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110;15 40 65 90 110];
%f=createFit(ang2, vel2, torque_male_flex);
f=createFit(vel2,ang2 ,torque_male_flex);
title('tva surface - male elbow flexion');
% xlabel('angle')
% ylabel('velocity')
xlabel('velocity')
ylabel('angle')
zlabel('torque')
hold on
plot3(X,Y,Z,'o','MarkerSize',10); %given point
%plot3(X,-50:300,Z,'o','MarkerSize',1); %Normal to point
plot3(X,Y,0:100,'o','MarkerSize',1); %Normal to point --> this is the direction I would like to find the intersection point, so in this Example I am looking for [60;60;?]
for i=0:0.01:100
%val=f(angle_flex,i);
val=f(angle_flex,i);
if (round(val,2)==Z)disp('intersection');
in=i;
end
end
%plot3(angle_flex,in,Z,'o','MarkerSize',10) %Intersection point
plot3(angle_flex,ang_vel,in,'o','MarkerSize',10) %Intersection point
% function [fitresult, gof] = createFit(ang2, vel2, torque_male_flex)
function [fitresult, gof] = createFit(vel2, ang2, torque_male_flex)
%CREATEFIT(ANG2,VEL2,TORQUE_MALE_FLEX)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : ang2
% Y Input : vel2
% Z Output: torque_male_flex
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 06-Mar-2020 12:04:25
%% Fit: 'untitled fit 1'.
[xData, yData, zData] = prepareSurfaceData( vel2, ang2, torque_male_flex );
% Set up fittype and options.
ft = 'thinplateinterp';
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
%legend( h, 'untitled fit 1', 'torque_male_flex vs. ang2, vel2', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'ang2', 'Interpreter', 'none' );
ylabel( 'vel2', 'Interpreter', 'none' );
zlabel( 'torque_male_flex', 'Interpreter', 'none' );
grid on
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by