Matlab Cylinder create and make a joint with another cylinder

5 views (last 30 days)
I have two questions about Cylinder in Matlab
How I can model a cylinder for example with diamater 2 and height 10 than another one with same dimension and make a joint or connect them together. After that if I rotate first cylinder the second one to move automatically.

Answers (1)

Mike Garrity
Mike Garrity on 4 Nov 2015
It's a bit verbose, but the simplest way is probably nested hgtransform objects . Here's a simple example:
[x,y,z] = cylinder;
g1 = hgtransform;
s1 = surface(2*x,2*y,10*z,'FaceColor','red','Parent',g1);
g2 = hgtransform('Parent',g1,'Matrix',makehgtform('translate',[0 0 10]));
s2 = surface(2*x,2*y,10*z,'FaceColor','blue','Parent',g2);
view(3)
axis equal
Now we can change the Matrix properties of the two hgtransforms to make the cylinders move.
m1 = g1.Matrix;
m2 = g2.Matrix;
for ang=0:.01:pi/3
g1.Matrix = m1 * makehgtform('xrotate',ang);
g2.Matrix = m2 * makehgtform('xrotate',ang);
drawnow
end
The basic idea is that when we change the Matrix of g1, every object parented to it (i.e. s1, g2, & s2) will get rotated. And when we change the Matrix of g2, every object parented to it (i.e. s2) will get rotated. And the transformation that's applied to s2 will be the product of the Matrix properties of g1 and g2.
Does that make sense?

Categories

Find more on Graphics Performance 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!