Skip to content

Implement the deCasteljau Algorithm and plot the Bezier Curve using t… #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions matlab/interpolations/Bezier.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function [] = Bezier(v, dim)
result = zeros(dim, 2);
i = 1;
for u = linspace(0,1,dim)
result(i,:) = deCasteljau(v, length(v) - 1, 0, u);
i++;
endfor

plot (result(1:dim,1), result(1:dim,2), 'r','LineWidth',2)
hold
plot(v(:,1), v(:,2),'LineWidth',2)
title('Bezier Curve for given points')
endfunction
33 changes: 33 additions & 0 deletions matlab/interpolations/deCasteljau.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Copyright (C) 2018 Stefan
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {@var{retval} =} Bezier (@var{input1}, @var{input2})
##
## @seealso{}
## @end deftypefn

## Author: Stefan <stefan@Specter>
## Created: 2018-10-20

#Finding a point on a Bezier Curve: DeCasteljau's Algorithm
function [result] = deCasteljau (v,i,j,t)
if i == 0
result = v(j + 1, :);
%v(j,0) = x coordinate; v(j,1) = y coordinate;
else
result = (1 - t) * deCasteljau(v,i - 1,j,t) + t * deCasteljau(v,i - 1, j + 1,t);
endif
endfunction