My code works as follows
Step1: Small curve is placed on a point of the intersection about which it should rotate
Step 2: Small curve is rotated about the point of intersection and kept rotating till it touches the bigger circle at point xc & yc.
Note The initial point about which the curve rotates lies on the larger circle & this curve keeps rotating till the upper end of the curve intersects the large circle. When this happens xc---> x coordinate of the intersection has two values which can be best explained with this image
Thus when 1 iteration is over we have 2 values of xc & yc [denote intersection coordinate]
I have written the code .xc & yc are obtained by polyxpoly() but they are not showing values for 5th & 7th iteration inside rotate () when I remove semi-colon,. The strange part is when I return the values of xc & yc to the main() they return all the 8 values for 8 for-loop iterations in main() but they do not show values for 5th & 7th iteration inside rotate()
Image to better understand the above statement click to see the image
When intersection occurs xc & yc store 2 values each.1st pair of value which denotes point about which rotation occurred and 2nd pair of value which denotes point obtained after upper end of curve touched the circle. My requirement is to be able to return both the values but I am unable to do it.
After 4 iterations I am unable to store both values of xc check the image
My code is as follows
clc,clear
r = 10; % arc length
R = 55; % radius of a circle
aa = 60*pi/180; % arc angle
ap = 0*pi/180; % arc position angle
k=0;
ind=[30 40 50 60 70 80];
t = linspace(0,pi/2);
[x,y] = pol2cart(t,R); % circle data
t1 = linspace(0,aa)-aa/2+ap;
[x1,y1] = pol2cart(t1,r); % arc data
% Intersection of x axis (y=0) and quarter circle
x_axis_range=1:1000;
y_val_on_x_axis=zeros(1,length(x_axis_range));
[x1rc,y1rc]=polyxpoly(x_axis_range,y_val_on_x_axis,x,y);
xc_s(1)=x1rc;
yc_s(1)=y1rc;
% x1rc=55;
% y1rc=0;
plot(x,y)
hold on
for z=1:8
[x1_rotated,y1_rotated,xc,yc,XC,YC]=rotate(x,y,x1,y1,x1rc,y1rc);
x1rc=xc;
y1rc=yc;
plot(x1_rotated,y1_rotated, 'r-');
axis equal
end
rotate()
function [x1_rotated,y1_rotated,xc,yc,XC,YC] = rotate(x,y,x1,y1,x1rc,y1rc)
[x1_p,y1_p]= placement(x,y,x1,y1,x1rc,y1rc);
theta =linspace(0,pi,500);
i=1;
xc=[];
yc=[];
xcen=x1rc;
ycen=y1rc;
ub=0;
%while isempty(xc)||xc==xcen && isempty(yc)||yc==ycen
while (isempty(xc)||abs(xc-xcen)<=10*eps(xcen)) && (isempty(yc)||abs(yc-ycen)<=10*eps(ycen))
% create a matrix of these points, which will be useful in future calculations
v = [x1_p;y1_p];
% choose a point which will be the center of rotation
x_center = xcen;
y_center = ycen;
% create a matrix which will be used later in calculations
center = repmat([x_center; y_center], 1, length(x1_p));
% define a theta degree counter-clockwise rotation matrix
R = [cos(theta(i)) -sin(theta(i)); sin(theta(i)) cos(theta(i))];
% do the rotation...
s = v - center; % shift points in the plane so that the center of rotation is at the origin
so = R*s; % apply the rotation about the origin
vo = so + center; % shift again so the origin goes back to the desired center of rotation
% this can be done in one line as:
% vo = R*(v - center) + center
% pick out the vectors of rotated x- and y-data
x1_rotated = vo(1,:);
y1_rotated = vo(2,:);
[xc,yc] = polyxpoly(x1_rotated,y1_rotated,x,y);
if length(xc)>1
XC=xc % to pass both the values of xc
YC=yc; % to pass both the values of yc
ubx=xc(1); lbx=xc(2);
uby=yc(2);lby=yc(1);
xc=xc(2);
yc=yc(2);
ub=[ubx uby];
lb=[lbx-4 lby];
end
i=i+1;
end
end
Due to this, my end result stops at 4th iteration and it looks like enter image description here
placement()
function [x1_p,y1_p] = placement(x,y,x1,y1,x1rc,y1rc)
xcen=x1rc;
ycen=y1rc;
% shifting arc-lower-end to (t(1),0) or (
delx=xcen-x1(1); % Finding the x difference between arc-lower-end x-coordinate & x(1)[circle]
dely=ycen-y1(1); % Finding the y difference between arc-lower-end y-coordinate & y(1) [circle]
x1_p=x1+delx;
y1_p=y1+dely;
end
Aucun commentaire:
Enregistrer un commentaire