کد رسم منحنی Bezier در متلب
- 1393/01/14
- بدون دیدگاه
در این پست سورس متفاوتی از برنامه رسم منحنی بزیر (Bezier) در متلب را خدمت شما ارایه می دهیم. این برنامه در متلب نوشته شده و رابط کاربری (GUI) نیز برای آن تهیه شده است.
Bezier
منحنی Bézier یک نوع منحنی پارامتریک می باشد که درعلوم گرافیکی و دیگر علوم کاربرد دارد. توسعه منحنای Bezier به سطوح Bezier می انجامد. در علوم گرافیک برداری، منحنی های Bezier جهت مدلسازی منحنی های هموار بکار می روند. این منحنی ها میتوانند دارای درجه های مختلفی باشند. درجه (مرتبه) نیز برای آنها تعریف می شود. این منحنی ها همچنین در انیمیشن سازی جهت کنترل حرکت بکار می روند.
این برنامه قابلیت افزودن نقاط، ویرایش آنها و حذف آنها را دارد. همچنین می توان محدوده محورها (Axis) را مشخص نمود.
در پست های قبل چند نمونه کد جهت رسم این منحنی قرار داده بودیم:
نرم افزار رسم منحنی بزیر (Bézier curve)
Bezier Curve Drawing in MATLAB – GUI
سورس کامل این برنامه بصورت زیر می باشد. این برنامه با Function نوشته شده است.
% ******************************************
% EngPedia.ir
% ******************************************
function bezierGUI
figure(‘un’,’n’,’pos’,[.1 .1 .8 .8],’numbert’,’off’,’menub’,’non’,…
‘name’,’Bezier’)
axes(‘un’,’n’,’pos’,[.05 .05 .8 .9],’buttondownfcn’,@go)
e1 = uicontrol(‘style’,’ed’,’un’,’n’,’pos’,[.88,.1,.08,.05],…
‘backgroundc’,[1,1,1],’string’,’0 5′,’fonts’,10,’fontn’,’courier’,…
‘callback’,@che);
e2 = uicontrol(‘style’,’ed’,’un’,’n’,’pos’,[.88,.05,.08,.05],…
‘backgroundc’,[1,1,1],’string’,’0 10′,’fonts’,10,’fontn’,’courier’,…
‘callback’,@che);
uicontrol(‘sty’,’text’,’un’,’n’,’pos’,[.86,.045,.02,.05],…
‘string’,’y’,’fonts’,12,’backgroundc’,get(gcf,’color’))
uicontrol(‘sty’,’text’,’un’,’n’,’pos’,[.86,.095,.02,.05],…
‘string’,’x’,’fonts’,12,’backgroundc’,get(gcf,’color’))
uicontrol(‘style’,’text’,’un’,’n’,’pos’,[.86,.15,.1,.025],…
‘backgroundc’,[1,1,1],’string’,’Axes Limits’,’fonts’,10,…
‘fontn’,’courier’,’backgroundc’,get(gcf,’color’));
uicontrol(‘style’,’push’,’un’,’n’,’pos’,[.86,.375,.1,.05],…
‘backgroundc’,[1,1,1],’string’,’Reset’,’fonts’,10,’fontn’,’courier’,…
‘callback’,@gg);
% reset button simply closes and reopens the GUI
function gg(varargin)
close(gcf)
bezierGUI
end
hg = uibuttongroup(‘un’,’n’,’pos’,[.86,.2,.1,.15],…
‘fontn’,’courier’,’fonts’,10);
h1 = uicontrol(‘sty’,’radio’,’parent’,hg,’un’,’n’,’pos’,[0,1/3,1,1/3],…
‘string’,’Edit’);
h2 = uicontrol(‘sty’,’radio’,’parent’,hg,’un’,’n’,’pos’,[0,2/3,1,1/3],…
‘string’,’Add’);
uicontrol(‘sty’,’radio’,’parent’,hg,’un’,’n’,’pos’,[0,0,1,1/3],…
‘string’,’Delete’);
set(findobj(‘style’,’radiobutton’),’fontsize’,12)
% changing the x or the y limits
function che(varargin)
xlim(str2num(get(e1,’string’))); %#ok<*ST2NM>
ylim(str2num(get(e2,’string’)));
end
% original points
P = [0 0; 1 5; 3 2; 5 10];
% create an initial plot
bemain(P)
% pressing on the axes
function go(varargin)
% get points on axes
xx1 = get(findobj(‘type’,’line’,’marker’,’o’),’xdata’);
yy1 = get(findobj(‘type’,’line’,’marker’,’o’),’ydata’);
p = double(vpa(get(gca,’currentpoint’),12));
% based on radio button chosen, do something different
% Edit
if get(hg,’selectedobject’) == h1
% get point closest to click
sst = (abs(p(1,1) – xx1) + abs(p(1,2) – yy1));
% change its x and y to match click point
P(sst == min(sst),:) = p(1,1:2);
% Add
elseif get(hg,’selectedobject’) == h2
% add point clicked to current points
P = [P;p(1,1:2)];
% Delete
else
% get point closest to click
sst = (abs(p(1,1) – xx1) + abs(p(1,2) – yy1));
% delete it
P(sst == min(sst),:) = [];
end
% draw the new Bezier curve with the new points
bemain(P)
end
% taken (comments included) from Bezier Curve Plotter by Sagar Aiya.
function bemain(P)
cla
che
Px = P(:,1);
Py = P(:,2);
% Number of points
r = 100;
% Calculate the Bezier curve
BezierCurve = bezier(Px,Py,r);
Bx = BezierCurve(:,1);
By = BezierCurve(:,2);
% Create figure
% Create axes
grid on
hold on
% Create plot
plot(Bx,By,’LineWidth’,1) %Bezier curve
plot(Px,Py,’ro’,’LineWidth’,1); % Control points
plot(Px,Py,’k-‘,’LineWidth’,1); % Lines between control points
end
% taken (comments included) from Bezier Curve Plotter by Sagar Aiya.
function BezierCurve = bezier(Px,Py,r)
% This function creates an Bezier Curve with r points and use’ the control points Px,Py
% Calculate the degree of the curve
n = length(Px)-1;
% Calculate the amount of change in the parameter u
du = 1/r;
% Calculate the binomial koefficienter
c = zeros(n+1,1);
bx = zeros(r+1,n+1);
by = zeros(r+1,n+1);
for i=0:n
c(i+1,1) = (factorial(n))/(factorial(i)*(factorial(n-i)));
% Calculate the Bernstein polynomium
for j=0:r
bx(j+1,i+1) = (c(i+1,1)*(j*du)^(i)*(1-(j*du)).^(n-i))*Px(i+1);
by(j+1,i+1) = (c(i+1,1)*(j*du)^(i)*(1-(j*du)).^(n-i))*Py(i+1);
end
end
Bx = zeros(r+1,1);
By = zeros(r+1,1);
% Calculate the Bezier Curve by sum up the Bernstein polynomials
for k=0:r
Bx(k+1,1) = sum(bx(k+1,1:n+1));
By(k+1,1) = sum(by(k+1,1:n+1));
end
% Output
BezierCurve = [Bx, By];
end
end
مطالب مرتبط
برچسب ها : Bézier, Bézier curve, curve, Matlab, رسم Bezier, رسم منحنی Bezier, رسم منحنی بزیر, کد Bezier, منحنی بزیر, نرم افزار رسم منحنی بزیر
دیدگاهتان را بنویسید
نشانی ایمیل منتشر نخواهد شد

مطالب جدید
- نرم افزار 4.2 I-Cliqq طراحی دوخت و گلدوزی
- نرم افزار PE Design v11.4 2025 طراحی دوخت و گلدوزی
- بسته آموزشی جامع SmartPlant 3D
- نرمافزار CFturbo 2025.1.1 طراحی توربوماشین، پمپ، فن و کمپرسورها
- نرم افزار Certara Phoenix 8.5 2025 مدلسازی فارماکوکینتیک و فارماکودینامیک
- نرم افزار Vensim PLE v10.2.2 2025 مدلسازی دینامیکی سیستم
- نرمافزار Flexi Complete v24.2 چاپ و برش در صنعت تابلوسازی
- نرمافزار EnRoute 2025 مجموعه کامل CAD/CAM در تابلوسازی
- نرمافزار Datamine Discover 2024 اکتشافات و مدلسازی منابع معدنی
- نرمافزار GEOVIA GEMS 6.8.7 2024 برنامهریزی فرآیندهای معدن

مطالب پربازدید

مطالب تصادفی
- نرم افزار Ansys medini analyze 2025R1 تحلیل ایمنی سیستمهای الکترونیک
- نرم افزار HTZ Communications 2024.7 طراحی و بهینهسازی شبکههای رادیویی
- شبیه سازی تصادف ماشین
- نرم افزار AVEVA E3D 4.1 2024 طراحی سازههای صنعتی و تاسیسات
- حل معادلات دیفرانسیل با مشتقات جزئی در MATLAB
- بررسی روش صریح و ضمنی (Explicit & Implicit)
- نرم افزار CONVAL 11.5 طراحی و تحلیل سیستمهای صنعتی
- نرم افزار Bentley Offshore 2024 پروژههای دریایی و سازههای فراساحلی
- نرمافزار Romax DT 2024.1 تحلیل سیستمهای انتقال قدرت
- نرم افزار SonarWiz 8.1 2024 شبیه سازی و نقشه برداری صوتی