Matlab Cylinder create and make a joint with another cylinder

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.

답변 (1개)

Mike Garrity
Mike Garrity 2015년 11월 4일
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?

카테고리

도움말 센터File Exchange에서 Animation에 대해 자세히 알아보기

질문:

2015년 11월 3일

답변:

2015년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by