gpt4 book ai didi

image - 在matlab中将图像添加到动画中

转载 作者:行者123 更新时间:2023-12-01 09:44:14 25 4
gpt4 key购买 nike

我在 matlab 中创建了一个行走的 3D 火柴人,我想添加一个图像作为他行走的地板。我不知道该怎么做。我看了一个有人添加图像作为背景的例子。这有点像我想要的,但我希望它显示为地板。我要给火柴人一个轨迹,让他在地板上行走。谁能指出我正确的方向。

好的,现在我明白了,多亏了 Andrey。

clear all

cyl = UnitCylinder(2);
sph = UnitSphere(2);

% Head
L1 = 2;

Head = translate(scale(sph,L1/2, L1/2, L1/2),0,0,L1+4.5);
Head.facecolor = 'yellow';

%Shoulder
r2 = 0.3;
L2 = 3;
Shoulder = translate(rotateX(scale(cyl,r2/2,r2/2,L2/2),90),0,0,5);
Shoulder.facecolor = 'red';


%Left Upper Arm
w1_s = [-20:4:20 20:-4:-20];
r3 = 0.3;
L3 = 2;
Upper_Arm_left = translate(scale(cyl,r3/2,r3/2,L3/2),0,0,-L3/2);
Upper_Arm_left.facecolor = 'red';

%Right Upper Arm
Upper_Arm_right = translate(scale(cyl,r3/2,r3/2,L3/2),0,0,-L3/2);
Upper_Arm_right.facecolor = 'red';

%Left Forearm
w2_s = [-5:1:5 5:-1:-5];
L3_f = 2.5;
Fore_Arm_left = translate(scale(cyl,r3/2,r3/2,L3_f/2),0,0,-L3_f/2);
Fore_Arm_left.facecolor = 'red';

%Right Forearm
Fore_Arm_right = translate(scale(cyl,r3/2,r3/2,L3_f/2),0,0,-L3_f/2);
Fore_Arm_right.facecolor = 'red';


%Chest
r4 = 2;
L4 = 2;
Chest = translate(scale(cyl,r4/2,r4/2,L4/2),0, 0, 5-L4/2);
Chest.facecolor = 'yellow';

%Weist
r5 = 1;
L5 = 2;
Weist = translate(scale(cyl,r5/2,r5/2,L5/2),0, 0, 5-L4-L5/2);
Weist.facecolor = 'yellow';

%Hip
L6 = 1.5;
Hip = translate(rotateX(scale(cyl,r2/2,r2/2,L6/2),90),0,0,5-L4-L5-r2/2);
Hip.facecolor = 'green';

%Left Upper Leg
r7 = 0.4;
L7 = 2.5;
L71 = (L6/2+r7/2);
L72 = 5-L7/2-L4-L5;
Upper_Leg_left = translate(scale(cyl,r7/2,r7/2,L7/2),0,0,-L7/2);
Upper_Leg_left.facecolor = 'green';

%Right Upper Leg
Upper_Leg_right = translate(scale(cyl,r7/2,r7/2,L7/2),0,0,-L7/2);
Upper_Leg_right.facecolor = 'green';

%Left Lower Leg
L7_f = 3;
Lower_Leg_left = translate(scale(cyl,r7/2,r7/2,L7_f/2),0,0,-L7_f/2);
Lower_Leg_left.facecolor = 'green';

%Right Lower Leg
Lower_Leg_right = translate(scale(cyl,r7/2,r7/2,L7_f/2),0,0,-L7_f/2);
Lower_Leg_right.facecolor = 'green';

angle1 = 0;
angle2 = 0;

for i = 1:120

angle1 = w1_s(rem(i,length(w1_s))+1);
angle2 = w2_s(rem(i,length(w1_s))+1);

Arm_left = combine(translate(rotateY(Fore_Arm_left,angle2),0,0,-L3), Upper_Arm_left);
Arm_right = combine(translate(rotateY(Fore_Arm_right,-angle2),0,0,-L3), Upper_Arm_right);

Arm_left = translate(rotateY(Arm_left,angle1),0,-L2/2,(5-L3/2)+L3/2);
Arm_right = translate(rotateY(Arm_right,-angle1),0,L2/2,(5-L3/2)+L3/2);

Leg_left = combine(translate(rotateY(Lower_Leg_left,-angle2),0,0,-L7), Upper_Leg_left);
Leg_right = combine(translate(rotateY(Lower_Leg_right,angle2),0,0,-L7), Upper_Leg_right);

Leg_left = translate(rotateY(Leg_left,-angle1),0,-L71,L72+L7/2);
Leg_right = translate(rotateY(Leg_right,angle1),0,L71,L72+L7/2);

Upper_Body = combine(Head, Shoulder, Arm_left, Arm_right, Chest, Weist);
Lower_Body = combine(Hip, Leg_left, Leg_right);
walker = combine(Upper_Body, Lower_Body);

cla
img = imread('peppers.png');
[X,Y] = ndgrid([-10 10],[-10 10]);
zImage = [-5 -5; -5 -5];
surf(X,Y,zImage,'CData',img,'FaceColor','texturemap');
% view([1 1 1]);
hold on
view(3)
set(gca,'xlim',[-10 10],'ylim',[-10 10],'zlim',[-6 6]);
renderpatch(walker);
camlight
box on
drawnow
pause(0.04)

end

我想得到类似这层楼的东西,但我不知道该怎么做。此人在他们的代码中使用了 .fig。这是他们使用的一部分。

F1 = open('background1.fig');
background_gca = gca;
F2 = figure(2);
.
.
.
clf(F2)
copyobj(background_gca,F2);
view([-40,25])
set(gca,'xlim',[-5 5],'ylim',[-5 5],'zlim',[0 10]);
renderpatch(walker);
camlight
box on
% axis off
drawnow;

example of the how I want mine to look

最佳答案

你有一个小的语法错误:

首先,你颠倒了 zy :

冲浪(xImage,zImage,yImage,...)

此外,您应该将 surf 视为一个表面。因此,所有 z 都应为 0

img = imread('peppers.png');
[X,Y] = ndgrid([-5 5],[-5 5]);
zImage = [0 0; 0 0];
surf(X,Y,zImage,'CData',img,'FaceColor','texturemap');
view([1 1 1]);

enter image description here

关于image - 在matlab中将图像添加到动画中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12766294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com