Perpendicular Surfaces of a Plot

4 views (last 30 days)
Tim Schaller
Tim Schaller on 25 Oct 2022
Edited: Tim Schaller on 25 Oct 2022
Hi there,
I have a qestion about some kind of a plot.
Down below you can see the plot of a bending that I created with the help of some of you.
Now my next task was to create the 2D Plot at the end which are the intersections of the very first plot, but lined up.
What i need to change at my plot is, that the cornes should be quarter circles.
So that the one in the middle will be a full cricle and the other ones have the stright section, but round corners.
Just normal splines won't solve my problem, becauce they are not quatercircles.
I hope, that somebody can held me.
Thank You
clear all
n = 3;
n1 = n-1;
a = 15; % Breite des Krummers entlang x
b = 10; % Höhe des Krümmers entlang y
P = [0 b;0 0;a 0]; % Punkte für Beziér-Spline Plot
T = 15; % Anazhl an Teilpunkten für den Plot
H = 6; % Höhe des Ausgangs
R = 1.5; % Radius des Eingangs
h = 4; % Breite des Ausgangs
syms t s(t)
B = bernsteinMatrix(n1,t);
bezierCurve = B*P;
s(t) = int(norm(diff(bezierCurve)),0,t);
snum = linspace(0,s(1),T);
for i = 1:T
tnum(i) = vpasolve(snum(i)==s(t),t); %vpasolve löst Gleichungen mit Symbolvariablen
end
px = double(subs(bezierCurve(:,1),t,tnum)).';
py = zeros(T,1);
pz = double(subs(bezierCurve(:,2),t,tnum)).';
plot3(px,py,pz,'b-o',"MarkerSize",4)
axis equal
axis tight
grid on
hold on
normalToCurve = diff(bezierCurve)*[0 1;-1 0];
normalToCurve = normalToCurve/norm(normalToCurve);
newNormalToCurve = [double(subs(normalToCurve(1),t,tnum))' double(subs(normalToCurve(2),t,tnum))'];
newNormalToCurvex = newNormalToCurve(:,1);
newNormalToCurvez = newNormalToCurve(:,2);
%%%%%%%%%%%Obere Linie
for i = 1:T
S = double(s((i-1)/(T-1)));
d = R*(1-S/double(s(1)))+(H/2)*S/double(s(1));
delta(i) = d;
end
delta = delta';
pxnew1 = px+newNormalToCurvex.*delta;
pznew1 = pz+newNormalToCurvez.*delta;
for i = 1:T
S = double(s((i-1)/(T-1)));
rhilfe = (h/2)*S/double(s(1));
r(i) = rhilfe;
end
r = r';
for i = 1:2
pynew1 = r*(-1)^i;
plot3(pxnew1,pynew1,pznew1,'r-o','MarkerSize',4)
end
pynew1a = - r;
pynew1b = r;
%%%%%%%%%%Untere Linie
delta = - delta;
pxnew2 = px+newNormalToCurvex.*delta;
pznew2 = pz+newNormalToCurvez.*delta;
for i = 1:2
pynew1 = r*(-1)^i;
plot3(pxnew2,pynew1,pznew2,'r-o','MarkerSize',4)
end
pynew2a = pynew1a;
pynew2b = pynew1b;
%%%%%%%%%%seitliche Linien (schwarz)
for i = 1:T
S = double(s((i-1)/(T-1)));
chilfe = R*(1-S/double(s(1)))+(h/2)*S/double(s(1));
c(i) = chilfe;
end
for i = 1:T
S = double(s((i-1)/(T-1)));
lhilfe = H/2*S/double(s(1));
l(i) = lhilfe;
end
l = l';
c = c';
pynew3 = ones(T,1).*c;
for i = 1:2
pxnew3 = px+newNormalToCurvex.*l*(-1)^i;
pznew3 = pz+newNormalToCurvez.*l*(-1)^i;
plot3(pxnew3,pynew3,pznew3,'k-o','MarkerSize',4)
pynew3 = -pynew3;
plot3(pxnew3,pynew3,pznew3,'k-o','MarkerSize',4)
end
pxnew3a = px-newNormalToCurvex.*l;
pxnew3b = px+newNormalToCurvex.*l;
pznew3a = pz-newNormalToCurvez.*l;
pznew3b = pz+newNormalToCurvez.*l;
pynew3a = pynew3;
pynew3b = -pynew3;
%%%%%%%%%%%%4Ecken
%%%vorne links/rechts (magenta)
Rnew = R*cos(pi/4);
for i = 1:T
S = double(s((i-1)/(T-1)));
jhilfe = Rnew*(1-S/double(s(1)))+(H/2)*S/double(s(1));
j(i) = jhilfe;
end
for i = 1:T
S = double(s((i-1)/(T-1)));
ehilfe = Rnew*(1-S/double(s(1)))+(h/2)*S/double(s(1));
e(i) = ehilfe;
end
j = j';
e = e';
pxnew4 = px+newNormalToCurvex.*j;
pznew4 = pz+newNormalToCurvez.*j;
for i = 1:2
pynew4 = ones(T,1).*e*(-1)^i;
plot3(pxnew4,pynew4,pznew4,'m-o',"MarkerSize",4)
end
pynew4a = -ones(T,1).*e;
pynew4b = ones(T,1).*e;
%%%%%vorne links/recht(grün)
pxnew5 = px-newNormalToCurvex.*j;
pznew5 = pz-newNormalToCurvez.*j;
for i = 1:2
pynew5 = ones(T,1).*e*(-1)^i;
plot3(pxnew5,pynew5,pznew5,'g-o',"MarkerSize",4)
end
pynew5a = pynew4a;
pynew5b = pynew4b;
% view([0 0])
hold off
pxgesamt = [px;pxnew1; pxnew1; pxnew2; pxnew2; pxnew3a;pxnew3b;pxnew3a;pxnew3b;pxnew4; pxnew4; pxnew5; pxnew5];
pygesamt = [py;pynew1a;pynew1b;pynew2a;pynew2b;pynew3a;pynew3a;pynew3b;pynew3b;pynew4a;pynew4b;pynew5a;pynew5b];
pzgesamt = [pz;pznew1; pznew1; pznew2; pznew2; pznew3a;pznew3b;pznew3a;pznew3b;pznew4; pznew4; pznew5; pznew5];
pgesamt = [pxgesamt pygesamt pzgesamt];
% plot3(pxgesamt,pygesamt,pzgesamt,"ko","MarkerSize",3)
axis equal
axis tight
grid on
% view([0 0])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Plot der Draufsicht
%x-Werte werden nicht benötigt
%y-Werte werden x-Werte
%z-Werte in Abhägigkeit von s(t) werden zu y
arclen = arclength(px,pz);
S = linspace(0,arclen,T);
%obere Linien
p2y1 = linspace(0,h/2,T);
for i = 1:T
z2t = R*(1-S(i)/arclen)+(H/2)*S(i)/arclen;
z2(i) = z2t;
end
z2 = z2';
p2z1 = z2;
plot(p2y1,p2z1,'r-o',"MarkerSize",3)
hold on
grid on
axis equal
axis tight
p2y1b = -p2y1;
plot(p2y1b,p2z1,'r-o',"MarkerSize",3)
%untere Linien
p2y2 = p2y1;
p2z2 = -p2z1;
plot(p2y2,p2z2,'r-o',"MarkerSize",3)
p2y2b = p2y1b;
plot(p2y2b,p2z2,'r-o',"MarkerSize",3)
%seitliche Linien
for i = 1:T
c2hilfe = R*(1-S(i)/arclen)+h/2*(S(i)/arclen);
c2(i) = c2hilfe;
end
c2 = c2';
p2y3 = c2;
p2z3 = linspace(0,H/2,T);
plot(p2y3,p2z3,'k-o',"MarkerSize",3)
p2z3b = -p2z3;
plot(p2y3,p2z3b,'k-o',"MarkerSize",3)
p2y3b = -p2y3;
plot(p2y3b,p2z3,'k-o',"MarkerSize",3)
plot(p2y3b,p2z3b,'k-o',"MarkerSize",3)
%oben vorne/hinten (magenta)
Rnew = R*cos(pi/4);
for i = 1:T
j2hilfe = Rnew*(1-S(i)/arclen)+(H/2)*S(i)/arclen;
j2(i) = j2hilfe;
end
for i = 1:T
e2hilfe = Rnew*(1-S(i)/arclen)+(h/2)*S(i)/arclen;
e2(i) = e2hilfe;
end
j2 = j2';
e2 = e2';
p2y4 = e2;
p2z4 = j2;
plot(p2y4,p2z4,'m-o',"MarkerSize",3)
p2y4b = -p2y4;
plot(p2y4b,p2z4,'m-o',"MarkerSize",3)
% unten vorne/hinten (grün)
p2z5 = -p2z4;
plot(p2y4,p2z5,'g-o',"MarkerSize",3)
plot(p2y4b,p2z5,'g-o',"MarkerSize",3)
hold off
for i = 1:T
pyt = [p2y1(i); p2y4(i); p2y3(i); p2y3(i); p2y4(i); p2y2(i); p2y2b(i); p2y4b(i);
p2y3b(i); p2y3b(i); p2y4b(i); p2y1b(i); p2y1(i)];
pzt = [p2z1(i); p2z4(i); p2z3(i); p2z3b(i); p2z5(i); p2z2(i); p2z2(i); p2z5(i);
p2z3b(i); p2z3(i); p2z4(i); p2z1(i); p2z1(i)];
plot(pyt,pzt,'-o',"MarkerSize",3)
hold on
end
axis equal
axis tight
grid on
hold off
function [arclen,seglen] = arclength(px,py,varargin)
% arclength: compute arc length of a space curve, or any curve represented as a sequence of points
% usage: [arclen,seglen] = arclength(px,py) % a 2-d curve
% usage: [arclen,seglen] = arclength(px,py,pz) % a 3-d space curve
% usage: [arclen,seglen] = arclength(px,py,method) % specifies the method used
%
% Computes the arc length of a function or any
% general 2-d, 3-d or higher dimensional space
% curve using various methods.
%
% arguments: (input)
% px, py, pz, ... - vectors of length n, defining points
% along the curve. n must be at least 2. Replicate
% points should not be present in the curve.
%
% method - (OPTIONAL) string flag - denotes the method
% used to compute the arc length of the curve.
%
% method may be any of 'linear', 'spline', or 'pchip',
% or any simple contraction thereof, such as 'lin',
% 'sp', or even 'p'.
%
% method == 'linear' --> Uses a linear chordal
% approximation to compute the arc length.
% This method is the most efficient.
%
% method == 'pchip' --> Fits a parametric pchip
% approximation, then integrates the
% segments numerically.
%
% method == 'spline' --> Uses a parametric spline
% approximation to fit the curves, then
% integrates the segments numerically.
% Generally for a smooth curve, this
% method may be most accurate.
%
% DEFAULT: 'linear'
%
%
% arguments: (output)
% arclen - scalar total arclength of all curve segments
%
% seglen - arclength of each independent curve segment
% there will be n-1 segments for which the
% arc length will be computed.
%
%
% unpack the arguments and check for errors
if nargin < 2
error('ARCLENGTH:insufficientarguments', ...
'at least px and py must be supplied')
end
n = length(px);
% are px and py both vectors of the same length?
if ~isvector(px) || ~isvector(py) || (length(py) ~= n)
error('ARCLENGTH:improperpxorpy', ...
'px and py must be vectors of the same length')
elseif n < 2
error('ARCLENGTH:improperpxorpy', ...
'px and py must be vectors of length at least 2')
end
% compile the curve into one array
data = [px(:),py(:)];
% defaults for method and tol
method = 'linear';
% which other arguments are included in varargin?
if numel(varargin) > 0
% at least one other argument was supplied
for i = 1:numel(varargin)
arg = varargin{i};
if ischar(arg)
% it must be the method
validmethods = {'linear' 'pchip' 'spline'};
ind = strmatch(lower(arg),validmethods);
if isempty(ind) || (length(ind) > 1)
error('ARCLENGTH:invalidmethod', ...
'Invalid method indicated. Only ''linear'',''pchip'',''spline'' allowed.')
end
method = validmethods{ind};
else
% it must be pz, defining a space curve in higher dimensions
if numel(arg) ~= n
error('ARCLENGTH:inconsistentpz', ...
'pz was supplied, but is inconsistent in size with px and py')
end
% expand the data array to be a 3-d space curve
data = [data,arg(:)]; %#ok
end
end
end
% what dimension do we live in?
nd = size(data,2);
% compute the chordal linear arclengths
seglen = sqrt(sum(diff(data,[],1).^2,2));
arclen = sum(seglen);
% we can quit if the method was 'linear'.
if strcmpi(method,'linear')
% we are now done. just exit
return
end
% 'spline' or 'pchip' must have been indicated,
% so we will be doing an integration. Save the
% linear chord lengths for later use.
chordlen = seglen;
% compute the splines
spl = cell(1,nd);
spld = spl;
diffarray = [3 0 0;0 2 0;0 0 1;0 0 0];
for i = 1:nd
switch method
case 'pchip'
spl{i} = pchip([0;cumsum(chordlen)],data(:,i));
case 'spline'
spl{i} = spline([0;cumsum(chordlen)],data(:,i));
nc = numel(spl{i}.coefs);
if nc < 4
% just pretend it has cubic segments
spl{i}.coefs = [zeros(1,4-nc),spl{i}.coefs];
spl{i}.order = 4;
end
end
% and now differentiate them
xp = spl{i};
xp.coefs = xp.coefs*diffarray;
xp.order = 3;
spld{i} = xp;
end
% numerical integration along the curve
polyarray = zeros(nd,3);
for i = 1:spl{1}.pieces
% extract polynomials for the derivatives
for j = 1:nd
polyarray(j,:) = spld{j}.coefs(i,:);
end
% integrate the arclength for the i'th segment
% using quadgk for the integral. I could have
% done this part with an ode solver too.
seglen(i) = quadgk(@(t) segkernel(t),0,chordlen(i));
end
% and sum the segments
arclen = sum(seglen);
% ==========================
% end main function
% ==========================
% begin nested functions
% ==========================
function val = segkernel(t)
% sqrt((dx/dt)^2 + (dy/dt)^2)
val = zeros(size(t));
for k = 1:nd
val = val + polyval(polyarray(k,:),t).^2;
end
val = sqrt(val);
end % function segkernel
end % function arclength

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!