To generate constant arc points on Archimedean Spiral
9 次查看(过去 30 天)
显示 更早的评论
Dear Sir/ Mam,
The code for constant angle has been attahced. In this code i want to modify and need to generate constant arc points on Archimedean Spiral instead of constant angle
clear all
clc
% Parameters
R = 0; %outer radius
b = 2; %incerement per rev, equivalent to feed
a = -20; %inner radius
n = round((R - a)./(b)); %number of revolutions and number of
th = 2*n*pi; %angle obtained for n number of revolution, for one revoultion 2*pi
desiredAngle = 10;% Desired constant angle between points
npt= 360/desiredAngle; %% number of points in each spiral
t= ((-a/(2))*npt);
theta = 0:th/t:th;
r= ((a + b.*theta./(2*pi)));
% Interpolate points along the Archimedean spiral with constant angle
interpPoints = interp1(theta, [r', theta'], 0:th/t:th);
% Extract interpolated r and theta values
interp_r = interpPoints(:, 1);
interp_theta = interpPoints(:, 2);
% Convert polar coordinates to Cartesian coordinates
x =(-interp_r.* cos(interp_theta))';
y = (-interp_r.* sin(interp_theta))';
% Plot the Archimedean spiral and equidistant points in terms of angle
figure;
plot((-r.* cos(theta)), (-r .* sin(theta)), 'LineWidth', 2); % Original Archimedean Spiral
hold on;
plot(x, y, '-o'); % Equidistant Points in terms of Angle
axis equal;
xlabel('X-axis');
ylabel('Y-axis');
title('Spiral Toolpath with Constant Angle');
legend('Original Archimedean Spiral', 'Equidistant Points in terms of Angle');
0 个评论
采纳的回答
Mathieu NOE
2023-12-11
hello
try this
also I prefer to have
R = 20; %outer radius
a = 0; %inner radius
instead of
R = 0; %outer radius
a = -20; %inner radius
as for me inner radius (or start point) is at the center and not the most outer point - same comment for the other point
code
% Parameters
R = 20; %outer radius
b = 2; %incerement per rev, equivalent to feed
a = 0; %inner radius
n = round((R - a)./(b)); %number of revolutions and number of
th = 2*n*pi; %angle obtained for n number of revolution, for one revoultion 2*pi
theta = linspace(0,th,n*360);
r= a + b.*theta./(2*pi);
% Convert polar coordinates to Cartesian coordinates
xr = r.* cos(theta);
yr = r.* sin(theta);
%% constant arc code
% curvilinear abscissa : s = integral of a*sqrt(1+theta²)
y = b*sqrt(1+theta.^2);
s = cumtrapz(theta,y);
desiredArcsPoints = 3*360; % n*360;% Desired arcs points
sd = linspace(0,s(end),desiredArcsPoints);
% Interpolate points along the Archimedean spiral with constant arc
ti = interp1(s, theta, sd); % angle values with constant arc spacing
r= a + b.*ti./(2*pi);
% Convert polar coordinates to Cartesian coordinates
x = r.* cos(ti);
y = r.* sin(ti);
% Plot the Archimedean spiral and equidistant points in terms of angle
figure;
plot(xr, yr, 'LineWidth', 2); % Original Archimedean Spiral
hold on;
plot(x, y, '-o'); % Equidistant Points in terms of Angle
axis equal;
xlabel('X-axis');
ylabel('Y-axis');
title('Spiral Toolpath with Constant Arc');
legend('Original Archimedean Spiral', 'Equidistant Points in terms of Arc');
2 个评论
Mathieu NOE
2023-12-12
try this
clear all
clc
% Parameters
R2 = 40; %outer radius (between this radius and R1 is constant arc increment)
R1 = 10; %intermediate radius (below this radius is constant angle increment)
b = 2; %incerement per rev, equivalent to feed
a = 0; %inner radius
n = round((R2 - a)./(b)); %number of revolutions and number of
th = 2*n*pi; %angle obtained for n number of revolution, for one revoultion 2*pi
theta = linspace(0,th,n*360);
r= a + b.*theta./(2*pi);
% Convert polar coordinates to Cartesian coordinates
xr = r.* cos(theta);
yr = r.* sin(theta);
%% constant angular increment section
ind1 = (r<=R1);
x1 = xr(ind1);
y1 = yr(ind1);
%% constant arc increment section
ind2 = (r>R1);
theta2 = theta(ind2);
% curvilinear abscissa : s = integral of a*sqrt(1+theta²)
y = b*sqrt(1+theta2.^2);
s = cumtrapz(theta2,y);
desiredArcsPoints = 3*360; % n*360;% Desired arcs points
sd = linspace(0,s(end),desiredArcsPoints);
% Interpolate points along the Archimedean spiral with constant arc
ti = interp1(s, theta2, sd); % angle values with constant arc spacing
r= a + b.*ti./(2*pi);
% Convert polar coordinates to Cartesian coordinates
x = r.* cos(ti);
y = r.* sin(ti);
% combine both data sets (below and above R1)
x = [x1 x];
y = [y1 y];
% Plot the Archimedean spiral
figure;
plot(xr, yr, 'LineWidth', 2); % Original Archimedean Spiral
hold on;
plot(x, y, '-o'); % Equidistant Points in terms of Angle then Arc
axis equal;
xlabel('X-axis');
ylabel('Y-axis');
title('Spiral Toolpath with Constant Arc');
legend('Original Archimedean Spiral', 'Equidistant Points in terms of Angle / Arc');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Standard File Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!