plot3d convers to plot3d in GUI

Discussion in 'MATLAB' started by wahyoe Unggul, May 13, 2011.

  1. hi all
    I plot 3d an object in the form of ordinary plot

    figure('Name','undeformed structure.....
    for i=1:(length(Support:),1)));
    plot3([X(i)+circlesize*2,X(i)-circlesize*2],-[Z(i),Z(i)],[Y(i),Y(i)],'r'); %line
    plot3(sin(0:0.1:pi*2)*circlesize/2+X(i),cos(0:0.1:pi*2)*Z(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Y(i),'r') %circle

    objects formed lines and circles of proportion, but if I move to a GUI
    axis([min(MinX)-margin, max(MaxX)+margin, min(MinY)-margin, max(MaxY)+margin, min(MinZ)-margin, max(MaxZ)+margin])
    axislimits=axis;
    circlesize=max([axislimits(2)-axislimits(1),axislimits(4)-axislimits(3),axislimits(6)-axislimits(5)])/40
    plot3([X(i)+circlesize*2,X(i)-circlesize*2],-[Z(i),Z(i)],[Y(i),Y(i)],'r'); % line
    plot3(sin(0:0.1:pi*2)*circlesize/2+X(i),cos(0:0.1:pi*2)*Z(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Y(i),'r')%circle

    to object to the line but still the proportion of objects was not proportion circle again, about whether the factors that cause differences in the results of the 3d plot.

    thanks
    wahyoe
     
    wahyoe Unggul, May 13, 2011
    #1
    1. Advertisements

  2. wahyoe Unggul

    Steven_Lord Guest

    Look at the help for the AXIS command. I believe what you're looking to do
    is "axis equal".
     
    Steven_Lord, May 13, 2011
    #2
    1. Advertisements

  3. hai lord
    I've tried but the results are also similar
     
    wahyoe Unggul, May 13, 2011
    #3
  4. wahyoe Unggul

    Steven_Lord Guest

    I can has picture of the non-GUI and GUI axes? [Sorry. Your use of "hai"
    reminded me of "I Can Has Cheezburger?" (http://icanhascheezburger.com/) so
    I wanted to have a little fun.]

    Seriously, please print the GUI and the non-GUI axes to image files, put
    them on an image hosting site, and post links to those files in your reply
    so the group can see the differences that you're seeing.
     
    Steven_Lord, May 13, 2011
    #4

  5. http://s1176.photobucket.com/albums/x329/wahyoe2/?action=view&current=untitled.jpg

    axes (handles.draw)
    axis equal
    for i=1:(length(Support:),1)));
    plot3([X(i)+circlesize*2,X(i)-circlesize*2],-[Z(i),Z(i)],[Y(i),Y(i)],'r');
    plot3(sin(0:0.1:pi*2)*circlesize/2+X(i),cos(0:0.1:pi*2)*Z(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Y(i),'r')
    plot3(sin(0:0.1:pi*2)*circlesize/2+X(i)+circlesize,cos(0:0.1:pi*2)*Z(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Y(i),'r')
    plot3(sin(0:0.1:pi*2)*circlesize/2+X(i)-circlesize,cos(0:0.1:pi*2)*Z(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Y(i),'r')

    because the script is too long, can I send the file to your email? and then mistakes can be posted
     
    wahyoe Unggul, May 13, 2011
    #5
  6. Seriously, please print the GUI and the non-GUI axes to image files, put

    http://s1176.photobucket.com/albums/x329/wahyoe2/?action=view&current=untitled.jpg

    axes (handles.draw)
    axis equal
    for i=1:(length(Support:),1)));
    plot3([X(i)+circlesize*2,X(i)-circlesize*2],-[Z(i),Z(i)],[Y(i),Y(i)],'r');
    plot3(sin(0:0.1:pi*2)*circlesize/2+X(i),cos(0:0.1:pi*2)*Z(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Y(i),'r')
    plot3(sin(0:0.1:pi*2)*circlesize/2+X(i)+circlesize,cos(0:0.1:pi*2)*Z(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Y(i),'r')
    plot3(sin(0:0.1:pi*2)*circlesize/2+X(i)-circlesize,cos(0:0.1:pi*2)*Z(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Y(i),'r')

    because the script is too long, can I send the file to your email? and then mistakes can be posted
     
    wahyoe Unggul, May 13, 2011
    #6
  7. wahyoe Unggul

    Steven_Lord Guest

    No. Please post the script here so that others can see it and offer
    suggestions as well. But before posting a really long script, see if you can
    come up with a shorter script that shows the same general behavior.
     
    Steven_Lord, May 13, 2011
    #7
  8. I'm not sure exactly what your trying to do, but 'axis equal' has caused problems for me a number of times, so I use daspect([1,1,1]), or daspect([1,1,1/5]) if the z scale needs to be streached.
    Taking a quick guess, if you're working in a GUI, you might be getting a different axis than you think you are. Try some basic commands like changing the tick markers, or turning them on and off, to see if you do have the right set when you're setting/getting.
    Hope this helps, Alan J.
     
    Alan Jennings, May 13, 2011
    #8
  9. % coord file
    1 0 0 4242.6
    2 4242.6 0 4242.6
    3 4242.6 0 0
    4 0 0 0
    5 2121.3 4000 2121.3

    % element file
    1 1 5 1 0
    2 2 5 2 0
    3 3 5 3 0
    4 4 5 4 0

    % Support file
    1 0 1 0
    2 0 1 0
    3 0 1 0
    4 0 1 0

    GUI
    function coordinat_Callback(hObject, eventdata, handles)
    coord=uigetfileuigetfile({'*.txt'}) % input coord file
    set(hObject,'Userdata',coord)

    function element_Callback(hObject, eventdata, handles)
    element=uigetfileuigetfile({'*.txt'}) % input element file
    set(hObject,'Userdata',element)

    function Support_Callback(hObject, eventdata, handles)
    Support=uigetfileuigetfile({'*.txt'}) % input element file
    set(hObject,'Userdata',Support)

    coord=get(handles.coordinat,'UserData');
    element=get(handles.element,'UserData');
    [AX,AY,AZ,circlesize,...
    spasi,Xsupport,Ysupport,Zsupport]=undeformedt3d( coord,...
    element,Support );
    typesupport=[Support:),2) Support:),3) Support:),4)];


    axes (handles.draw)
    axis equal
    for i=1:(length(element:),1)));
    hold on
    plot3 (AX(i,:),AZ(i,:),AY(i,:),'-g.','LineWidth',1);
    end

    for i=1:(length(Support:),1)));
    if typesupport(i,:)==[1 1 1]
    plot3([Xsupport(i),Xsupport(i)-circlesize,Xsupport(i)+circlesize,Xsupport(i)],...
    -[Zsupport(i),Zsupport(i),Zsupport(i),Zsupport(i)],...
    [Ysupport(i),Ysupport(i)-circlesize,Ysupport(i)-circlesize,Ysupport(i)],'r')
    elseif typesupport(i,:)==[0 1 0]
    plot3([Xsupport(i)+circlesize*2,Xsupport(i)-circlesize*2],-[Zsupport(i),Zsupport(i)],[Ysupport(i),Ysupport(i)],'r');
    plot3(sin(0:0.1:pi*2)*circlesize/2+Xsupport(i),cos(0:0.1:pi*2)*Zsupport(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Ysupport(i),'r')
    else

    end
    end


    % function file
    function [AX,AY,AZ,MaxX,MinX,MinY,MaxY,MinZ,MaxZ,circlesize,...
    spasi,Xsupport,Ysupport,Zsupport]=undeformedt3d( coord,...
    element,Support )
    Joint=coord:),1);
    m=size(element,1);
    Xj=zeros(1,m);
    Xk=Xj;
    Yj=Xj;
    Yk=Xj;
    Zj=Xj;
    Zk=Xj;
    % Matriks Xj, Xy, Yj, Yk, Zj dan Zk
    for i=1:m
    ij=find(Joint==element(i,2));
    ik=find(Joint==element(i,3));
    Xj(i)=coord(ij,2);
    Xk(i)=coord(ik,2);
    Yj(i)=coord(ij,3);
    Yk(i)=coord(ik,3);
    Zj(i)=coord(ij,4);
    Zk(i)=coord(ik,4);
    end


    AX=[Xj' Xk'];
    AY=[Yj' Yk'];
    AZ =-[Zj' Zk'];

    MinX=min([Xj Xk Xj]);
    MaxX=max([Xj Xk Xk]);
    MinY=min([Yj Yk Yj]);
    MaxY=max([Yj Yk Yk]);
    MinZ=min([Zj Zk Zj]);
    MaxZ=max([Zj Zk Zk]);

    spasi=0.1*max([MaxX-MinX MaxY-MinY MaxZ-MinZ]);
    circlesize=0.05*max([MaxX-MinX MaxY-MinY MaxZ-MinZ]);


    typesupport=([Support:),2) Support:),3) Support:),4)])
    pos_support=([coord(Support:),1),2) coord(Support:),1),3) coord(Support:),1),4)]);
    Xsupport=pos_support:),1);
    Ysupport=pos_support:),2);
    Zsupport=pos_support:),3);
     
    wahyoe Unggul, May 13, 2011
    #9
  10. % coord file
    1 0 0 4242.6
    2 4242.6 0 4242.6
    3 4242.6 0 0
    4 0 0 0
    5 2121.3 4000 2121.3

    % element file
    1 1 5 1 0
    2 2 5 2 0
    3 3 5 3 0
    4 4 5 4 0

    % Support file
    1 0 1 0
    2 0 1 0
    3 0 1 0
    4 0 1 0

    GUI
    function coordinat_Callback(hObject, eventdata, handles)
    coord=uigetfileuigetfile({'*.txt'}) % input coord file
    set(hObject,'Userdata',coord)

    function element_Callback(hObject, eventdata, handles)
    element=uigetfileuigetfile({'*.txt'}) % input element file
    set(hObject,'Userdata',element)

    function Support_Callback(hObject, eventdata, handles)
    Support=uigetfileuigetfile({'*.txt'}) % input element file
    set(hObject,'Userdata',Support)

    coord=get(handles.coordinat,'UserData');
    element=get(handles.element,'UserData');
    [AX,AY,AZ,circlesize,...
    spasi,Xsupport,Ysupport,Zsupport]=undeformedt3d( coord,...
    element,Support );
    typesupport=[Support:),2) Support:),3) Support:),4)];


    axes (handles.draw)
    axis equal
    for i=1:(length(element:),1)));
    hold on
    plot3 (AX(i,:),AZ(i,:),AY(i,:),'-g.','LineWidth',1);
    end

    for i=1:(length(Support:),1)));
    if typesupport(i,:)==[1 1 1]
    plot3([Xsupport(i),Xsupport(i)-circlesize,Xsupport(i)+circlesize,Xsupport(i)],...
    -[Zsupport(i),Zsupport(i),Zsupport(i),Zsupport(i)],...
    [Ysupport(i),Ysupport(i)-circlesize,Ysupport(i)-circlesize,Ysupport(i)],'r')
    elseif typesupport(i,:)==[0 1 0]
    plot3([Xsupport(i)+circlesize*2,Xsupport(i)-circlesize*2],-[Zsupport(i),Zsupport(i)],[Ysupport(i),Ysupport(i)],'r');
    plot3(sin(0:0.1:pi*2)*circlesize/2+Xsupport(i),cos(0:0.1:pi*2)*Zsupport(i),cos(0:0.1:pi*2)*circlesize/2-circlesize/2+Ysupport(i),'r')
    else

    end
    end


    % function file
    function [AX,AY,AZ,MaxX,MinX,MinY,MaxY,MinZ,MaxZ,circlesize,...
    spasi,Xsupport,Ysupport,Zsupport]=undeformedt3d( coord,...
    element,Support )
    Joint=coord:),1);
    m=size(element,1);
    Xj=zeros(1,m);
    Xk=Xj;
    Yj=Xj;
    Yk=Xj;
    Zj=Xj;
    Zk=Xj;
    % Matriks Xj, Xy, Yj, Yk, Zj dan Zk
    for i=1:m
    ij=find(Joint==element(i,2));
    ik=find(Joint==element(i,3));
    Xj(i)=coord(ij,2);
    Xk(i)=coord(ik,2);
    Yj(i)=coord(ij,3);
    Yk(i)=coord(ik,3);
    Zj(i)=coord(ij,4);
    Zk(i)=coord(ik,4);
    end


    AX=[Xj' Xk'];
    AY=[Yj' Yk'];
    AZ =-[Zj' Zk'];

    MinX=min([Xj Xk Xj]);
    MaxX=max([Xj Xk Xk]);
    MinY=min([Yj Yk Yj]);
    MaxY=max([Yj Yk Yk]);
    MinZ=min([Zj Zk Zj]);
    MaxZ=max([Zj Zk Zk]);

    spasi=0.1*max([MaxX-MinX MaxY-MinY MaxZ-MinZ]);
    circlesize=0.05*max([MaxX-MinX MaxY-MinY MaxZ-MinZ]);


    typesupport=([Support:),2) Support:),3) Support:),4)])
    pos_support=([coord(Support:),1),2) coord(Support:),1),3) coord(Support:),1),4)]);
    Xsupport=pos_support:),1);
    Ysupport=pos_support:),2);
    Zsupport=pos_support:),3);
     
    wahyoe Unggul, May 13, 2011
    #10
  11. I several times to change the axis, but the results are also similar
    wahyoe
     
    wahyoe Unggul, May 13, 2011
    #11
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.