Verfasst am: 23.12.2011, 18:08
Titel: Kriessegment in matlab
Hi zusammen,
ich habe folgendes poblem. ich soll ein Kreissegment mit Matlab zeichnen, welches den schnittpunkt zweier geraden die sich schneiden verundet. Kann mir da jmd weiterhelfen wie man dieses problem angehen könnte . evtl mit einer schleife?
Verfasst am: 25.12.2011, 18:39
Titel: Re: Kriessegment in matlab
Hallo,
Für ein Kreissegment benötigt man einen Mittelpunkt, zwei Geraden und den Radius. Mit dem Ausdruck "Schnittpunkt verrunden" kann ich nichts anfangen.
Da dies eine Hausaufgabe zu sein scheint, solltest Du zeigen, was Du bisher gemacht hast und welche konkreten, Matlab betreffenden Schwierigkeiten aufgetreten sind.
Hi danke für die schnelle Antwort.
Den Winkel und die Geraden hab ich schon ich stelle mal kurz rein was ich schon habe.
%[M,success] = mlpa01_math(g1,g2,R)
close all
clear all
clc
%-----Rundungssegemnt-------
%----Anlegen der Struckturvariablen g1 und g2------
g1 = struct('XWertP1',7,'YWertP1',20,'ZWertP1',0,'XWertP2',7,'YWertP2',1,'ZWertP2',0);
g2 = struct('XWertP3',2,'YWertP3',4,'ZWertP3',0,'XWertP4',10,'YWertP4',4,'ZWertP4',0);
%----Zugreifen auf Elemnte der Strukturvariablen und erstellen eines
%jeweiligen Vektors--------------------------------------------------------
P1 = [g1.XWertP1 g1.YWertP1 g1.ZWertP1]';
P2 = [g1.XWertP2 g1.YWertP2 g1.ZWertP2]';
P3 = [g2.XWertP3 g2.YWertP3 g2.ZWertP3]';
P4 = [g2.XWertP4 g2.YWertP4 g2.ZWertP4]';
%----Matrix der Richtungsvektoren -------------------------------------
m = P2-P1;
b = P3-P1;
n = P4-P3;
B = [m -n];
%------Die Bedingung 'Success' überprüfen----------------------------------
if rank(B) == rank([B,b]);
if rank(B) == size(B,2);
success = 1
disp('Schnittpunkt')
x = B\b;
v = x(1);
s = x(2);
else
success = 0
M = []
disp('identisch')
return
end
else
disp('windschief')
return
end
%-------Den Schnittpunkt A ausgeben----------------------------------------
A = P1+ v*m
%--------Bestimmung des normalen Vektors der Ebene g1 und g2-----------
y= cross(m,n); %der normalen Vektor auf der Ebenene bestehen aus m,n
n1= cross(y,n); %der senkrechte Vektor zur Geraden g2
%----------Berechnung des Schnittwinkels zwischen den geraden--------------
alpha = acosd((m.*n)/(abs(m).*abs(n)));
%----------Berechnung von c---------------------
c=(R/(cosd(90)-(alpha/2)));%Wo is der Fehler???????????
%-----Berechnung von M-----------------------------------------------------
n2 = m/abs(m);
n3 = n/abs(n);
n4 = (n+m)/abs(n+m);
M = A+c
------------------------------------------------------------------------------------------Bis hier sind die mathematischen Parameter-------------------------------
--------------------------------------------------------------------------------------
%function [] = mlpa01_plot(g1,g2,R,M)
cla;%löscht figure leer
figure(1)
hold on
axis([0 50 0 50])
line([P1(1) P2(1)],[P1(2) P2(2)],[P1(3) P2(3)],'Marker','.','LineStyle','-')
grid on
line([P3(1) P4(1)],[P3(2) P4(2)],[P3(3) P4(3)],'Marker','.','LineStyle','-')
und das hier zum PLot.
--------------------------------------------------------------------------------------
Und hier die gui
function varargout = GUI_Kreissegment(varargin)
% GUI_KREISSEGMENT M-file for GUI_Kreissegment.fig
% GUI_KREISSEGMENT, by itself, creates a new GUI_KREISSEGMENT or raises the existing
% singleton*.
%
% H = GUI_KREISSEGMENT returns the handle to a new GUI_KREISSEGMENT or the handle to
% the existing singleton*.
%
% GUI_KREISSEGMENT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_KREISSEGMENT.M with the given input arguments.
%
% GUI_KREISSEGMENT('Property','Value',...) creates a new GUI_KREISSEGMENT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_Kreissegment_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_Kreissegment_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUI_Kreissegment
% Last Modified by GUIDE v2.5 23-Dec-2011 21:02:15
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_Kreissegment_OpeningFcn, ...
'gui_OutputFcn', @GUI_Kreissegment_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before GUI_Kreissegment is made visible.
function GUI_Kreissegment_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUI_Kreissegment (see VARARGIN)
% Choose default command line output for GUI_Kreissegment
handles.output = hObject;
% UIWAIT makes GUI_Kreissegment wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_Kreissegment_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in Berechne_pushbutton.
function Berechne_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to Berechne_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%erstellen der Variablen
g1=zeros(6,1);
g2=zeros(6,1);
%zuordnen der feldern zu den variablen
g1(1,1)=str2num(get(handles.input1_g1,'String'));
g1(2,1)=str2num(get(handles.input2_g1,'String'));
g1(3,1)=str2num(get(handles.input3_g1,'String'));
g1(4,1)=str2num(get(handles.input4_g1,'String'));
g1(5,1)=str2num(get(handles.input5_g1,'String'));
g1(6,1)=str2num(get(handles.input6_g1,'String'));
%aufruf der Mathfundktion
[M,success]=mlpa01_math(g1,g2,R);
%Fehlermeldung falls ein feld lehr ist...muss man für jedes Feld extra
%machen nur beispielhaft
if isempty(g1(1,1))
errordlg('Bitte ALLE Daten eingeben!!!')
return
end
%für den plot
axes(handles.axes1);
%aufruf der plotfunktion
mlpa01_plot(g1,g2,R,M);
%Umwandlung des Mittelpunkt Koordinaten in String--------------------------------
mx=num2str(M(1,1));
my=num2str(M(2,1));
mz=num2str(M(3,1));
%Ausgabe des Mittelpunkts in die Stringfelder-----------------------
set(handles.mx,'String',mx);
set(handles.my,'String',my);
set(handles.mz,'String',mz);
function input1_g1_Callback(hObject, eventdata, handles)
% hObject handle to input1_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input1_g1 as text
% str2double(get(hObject,'String')) returns contents of input1_g1 as a double
% --- Executes during object creation, after setting all properties.
function input1_g1_CreateFcn(hObject, eventdata, handles)
% hObject handle to input1_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input2_g1_Callback(hObject, eventdata, handles)
% hObject handle to input2_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input2_g1 as text
% str2double(get(hObject,'String')) returns contents of input2_g1 as a double
% --- Executes during object creation, after setting all properties.
function input2_g1_CreateFcn(hObject, eventdata, handles)
% hObject handle to input2_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input3_g1_Callback(hObject, eventdata, handles)
% hObject handle to input3_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input3_g1 as text
% str2double(get(hObject,'String')) returns contents of input3_g1 as a double
% --- Executes during object creation, after setting all properties.
function input3_g1_CreateFcn(hObject, eventdata, handles)
% hObject handle to input3_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input1_g2_Callback(hObject, eventdata, handles)
% hObject handle to input1_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input1_g2 as text
% str2double(get(hObject,'String')) returns contents of input1_g2 as a double
% --- Executes during object creation, after setting all properties.
function input1_g2_CreateFcn(hObject, eventdata, handles)
% hObject handle to input1_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input2_g2_Callback(hObject, eventdata, handles)
% hObject handle to input2_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input2_g2 as text
% str2double(get(hObject,'String')) returns contents of input2_g2 as a double
% --- Executes during object creation, after setting all properties.
function input2_g2_CreateFcn(hObject, eventdata, handles)
% hObject handle to input2_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input3_g2_Callback(hObject, eventdata, handles)
% hObject handle to input3_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input3_g2 as text
% str2double(get(hObject,'String')) returns contents of input3_g2 as a double
% --- Executes during object creation, after setting all properties.
function input3_g2_CreateFcn(hObject, eventdata, handles)
% hObject handle to input3_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input4_g2_Callback(hObject, eventdata, handles)
% hObject handle to input4_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input4_g2 as text
% str2double(get(hObject,'String')) returns contents of input4_g2 as a double
% --- Executes during object creation, after setting all properties.
function input4_g2_CreateFcn(hObject, eventdata, handles)
% hObject handle to input4_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input5_g2_Callback(hObject, eventdata, handles)
% hObject handle to input5_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input5_g2 as text
% str2double(get(hObject,'String')) returns contents of input5_g2 as a double
% --- Executes during object creation, after setting all properties.
function input5_g2_CreateFcn(hObject, eventdata, handles)
% hObject handle to input5_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input6_g2_Callback(hObject, eventdata, handles)
% hObject handle to input6_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input6_g2 as text
% str2double(get(hObject,'String')) returns contents of input6_g2 as a double
% --- Executes during object creation, after setting all properties.
function input6_g2_CreateFcn(hObject, eventdata, handles)
% hObject handle to input6_g2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input4_g1_Callback(hObject, eventdata, handles)
% hObject handle to input4_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input4_g1 as text
% str2double(get(hObject,'String')) returns contents of input4_g1 as a double
% --- Executes during object creation, after setting all properties.
function input4_g1_CreateFcn(hObject, eventdata, handles)
% hObject handle to input4_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input5_g1_Callback(hObject, eventdata, handles)
% hObject handle to input5_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input5_g1 as text
% str2double(get(hObject,'String')) returns contents of input5_g1 as a double
% --- Executes during object creation, after setting all properties.
function input5_g1_CreateFcn(hObject, eventdata, handles)
% hObject handle to input5_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function input6_g1_Callback(hObject, eventdata, handles)
% hObject handle to input6_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input6_g1 as text
% str2double(get(hObject,'String')) returns contents of input6_g1 as a double
% --- Executes during object creation, after setting all properties.
function input6_g1_CreateFcn(hObject, eventdata, handles)
% hObject handle to input6_g1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit19_Callback(hObject, eventdata, handles)
% hObject handle to edit19 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit19 as text
% str2double(get(hObject,'String')) returns contents of edit19 as a double
% --- Executes during object creation, after setting all properties.
function edit19_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit19 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit20_Callback(hObject, eventdata, handles)
% hObject handle to edit20 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit20 as text
% str2double(get(hObject,'String')) returns contents of edit20 as a double
% --- Executes during object creation, after setting all properties.
function edit20_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit20 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit21_Callback(hObject, eventdata, handles)
% hObject handle to edit21 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit21 as text
% str2double(get(hObject,'String')) returns contents of edit21 as a double
% --- Executes during object creation, after setting all properties.
function edit21_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit21 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function rundungssekment_Callback(hObject, eventdata, handles)
% hObject handle to rundungssekment (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of rundungssekment as text
% str2double(get(hObject,'String')) returns contents of rundungssekment as a double
% --- Executes during object creation, after setting all properties.
function rundungssekment_CreateFcn(hObject, eventdata, handles)
% hObject handle to rundungssekment (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
ein genaues Problem konnte ich aus deiner Antwort nicht erkennen. Bitte nutze den CODE-Button und versuche nicht soviele Funktionen und englische Kommentare zu posten.
Viele Grüße
Coja
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.