function [x, y, z] = flywheel( p, axi, axr, axl, inr, outr, len, flw, axl2) % constuct the mesh for a flywheel % % flywheel( p, axr, axl, inr, outr, len, flw, axl2) % % p is the position of the center of the face % axi the inner radius of the bearing % axr the outer radius of the bearing % axl the length of the bearing % inr the radius inside the rim % outr the radius outside the rim % len the length of the rim % flw the flange width % axl2 the length of the back side of the axle axial = 20; global rotational radial = 20; % front face of the axle ll = linspace(0, axl, axial); thl = linspace(0, 2*pi, rotational); rl = linspace(axi, axr, radial); [r, th] = meshgrid( rl, thl ); x1 = p(1) * ones(size(r)); y1 = p(2) + r.*cos(th); z1 = p(3) + r.*sin(th); % outer rim of the axle [l, th] = meshgrid(ll, thl); x2 = p(1) + l; y2 = p(2) + axr*cos(th); z2 = p(3) + axr*sin(th); % front face of the flange rl = linspace(axr, inr, radial); [r, th] = meshgrid( rl, thl ); x3 = (p(1) + axl) * ones(size(r)); y3 = p(2) + r.*cos(th); z3 = p(3) + r.*sin(th); % inner face of the rim [l, th] = meshgrid(linspace(axl, 0, axial), thl); x4 = p(1) + l; y4 = p(2) + inr*cos(th); z4 = p(3) + inr*sin(th); % front face of the rim rl = linspace(inr, outr, radial); [r, th] = meshgrid( rl, thl ); x5 = p(1) * ones(size(r)); y5 = p(2) + r.*cos(th); z5 = p(3) + r.*sin(th); % outer rim of the flywheel [l, th] = meshgrid(linspace(0, len, axial), thl); x6 = p(1) + l; y6 = p(2) + outr*cos(th); z6 = p(3) + outr*sin(th); % back face of the rim rl = linspace(outr, inr, radial); [r, th] = meshgrid( rl, thl ); x7 = (p(1) + len) * ones(size(r)); y7 = p(2) + r.*cos(th); z7 = p(3) + r.*sin(th); % back face of the rim rl = linspace(inr, axr, radial); [r, th] = meshgrid( rl, thl ); x8 = (p(1) + axl + flw) * ones(size(r)); y8 = p(2) + r.*cos(th); z8 = p(3) + r.*sin(th); % back face of the axle rl = linspace(axr, axi, radial); [r, th] = meshgrid( rl, thl ); xn = (p(1) + axl + flw + axl2) * ones(size(r)); yn = p(2) + r.*cos(th); zn = p(3) + r.*sin(th); x = [x1 x2 x3 x4 x5 x6 x7 x8 xn]; y = [y1 y2 y3 y4 y5 y6 y7 y8 yn]; z = [z1 z2 z3 z4 z5 z6 z7 z8 zn];