필터 지우기
필터 지우기

Keeping axes still, while transforming objects

조회 수: 3 (최근 30일)
Julian Büchel
Julian Büchel 2017년 9월 12일
댓글: Walter Roberson 2020년 6월 13일
Hi,
in this ( https://www.youtube.com/watch?v=FrpG-KP_Tg8 ) video at the end, a transformation is applied. I have adopted the code from the video, but somehow my axes get scaled too. This is my code:
clc;
close all;
clear all;
comPort = '/dev/cu.usbmodem1421';
if(~exist('serialFlag','var'));
[fsr.s,serialFlag] = setupSerial(comPort);
end
if(~exist('h','var')|| ~ishandle(h))
h = figure(1);
end
if(~exist('text1','var'))
text1 = uicontrol('Style','text', 'String', 'X: 0 degress',...
'pos',[450 100 100 25],'parent',h);
end
if(~exist('text2','var'))
text2 = uicontrol('Style','text', 'String', 'Y: 0 degress',...
'pos',[450 75 100 25],'parent',h);
end
if(~exist('button','var'))
button = uicontrol('Style','togglebutton', 'String', 'Stop & Close Serial Port',...
'pos',[0 0 200 25],'parent',h);
end
weights=[0 700 800 900 1000 1500 2000 2500 3000 4000 4999];
%Hier noch mehr hinzufuegen
m1 = zeros(length(weights),1);
length(weights)
%Read values for each weight and assign it
for i=2:length(weights)
mbox = msgbox(['Place ' num2str(weights(i)) ' grams on FSR.']); uiwait(mbox);
m1(i)= readFSR(fsr)
while (m1(i)<m1(i-1))
m1(i)=readFSR(fsr);
end
end
m=m1.';
P1=polyfit(m,weights,2)
%250 is the max weight. 250g. Change to 20 000!
myaxes = axes('xlim',[-20 20],'ylim',[-20 20],'zlim',[0 6]);
view(3);
grid on;
axis equal;
hold on;
%Draw sphere
[xsphere, ysphere, zsphere] = sphere();
h(1) = surface(xsphere,ysphere,zsphere);
combinedobject = hgtransform('parent',myaxes);
set(h,'parent',combinedobject)
drawnow
while (get(button,'Value')==0)
[voltage]=readFSR(fsr);
mass = polyval(P1,voltage); %in g
if(mass>0)
force = mass*9.81; %in newton
set(text1,'String',['Mass: ' num2str(mass) ' g']);
set(text2,'String',['Force: ' num2str(force) ' N']);
translation = makehgtform('translate',[0 0 mass/1000]); %in kg's
set(combinedobject,'matrix',translation);
%Scale sphere
scaling = makehgtform('scale', mass/10000);
set(combinedobject,'matrix',scaling);
set(combinedobject,'matrix',translation*scaling);
drawnow
end
pause(0.1);
end
closeSerial;
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 6월 13일
http://www.matlabarduino.org/force.html is the source of the tutorial

댓글을 달려면 로그인하십시오.

채택된 답변

Tim Berk
Tim Berk 2017년 9월 19일
I can't reproduce this as your script won't run on its own, but I think the problem is that
axis equal
Overwrites the limits stated in
myaxes = axes('xlim',[-20 20],'ylim',[-20 20],'zlim',[0 6]);
You can solve this by reversing the order in which the axes limits and "axis equal" option are called, i.e.
myaxes = axes;
view(3);
grid on;
axis equal;
axis([-20 20 -20 20 0 6])
hold on;
Cheers,
Tim

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by