Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [x y z] = egg(top,bottom,dt,mode)
- %
- % Auteur: Simon Demaré
- % Date: 27/10/2014
- % Description: Produit une sphère ou la dérivée d'une sphère en fonction
- % des valeurs de top et bottom sachant que:
- % top = 1 et bottom = 1 donne une sphère
- % top = 2 et bottom = 1 donne un oeuf
- % top = 1 et bottom = 2 donne un oeuf inversé
- % etc. Le programme est basé sur l'utilisation de NURBS.
- % Merci à Paul Decroes pour l'aide à la compréhension
- T = [0,0,0,1,1,2,2,3]; %n=7 car 8 noeuds (donnée)
- S = [0,0,0,1,1,2,2,3,3,4,4,5]; %m=11 car 12 noeuds(donnée)
- tp=top+bottom;
- %R et H pour sphère valent [0 2 2 2 0] et [0 0 1 2 2]
- %Bel oeuf H = [0 0 1 4 4]
- R= [0 2 2 2 0]; %Rayons des différents cercles
- Premier = 0;
- Dernier = top*2;
- %H = [Premier Premier 1 Dernier Dernier] %Hauteurs des couches constructrices
- H = [-bottom -bottom 0 top top]
- %middle = 0
- % La forme de base est un carré de 2 de coté. Les points sont ceux
- % du périmètre du carré avec un pas de 1 (c/2). Les Xc et Yc sont donc
- % correspondants à ces points
- p = 2; %degré des surfaces (donnée)
- Xc =[0 0 1 2 2 2 1 0 0]./2;
- Yc =[1 2 2 2 1 0 0 0 1]./2;
- Xc = Xc - mean(Xc);
- Yc = Yc - mean(Yc);
- Zc = ones(size(Xc));
- a=sqrt(2)/2;
- Wc = [1 a 1 a 1 a 1 a 1] ;
- X = Xc' * R;
- Y = Yc' * R;
- Z = Zc' * H;
- W = Wc' * [1 a 1 a 1];
- nt = length(T) - 1;
- t = [T(p+1):dt:T(nt-p+1)];
- for i=0:nt-p-1
- Bt(i+1,:) = b(t,T,i,p);
- end
- ns = length(S) - 1;
- s = [S(p+1):dt:S(ns-p+1)];
- for i=0:ns-p-1
- Bs(i+1,:) = b(s,S,i,p);
- end
- w = Bs' * W * Bt;
- x = Bs' * (W .* X) * Bt ./ w;
- y = Bs' * (W .* Y) * Bt ./ w;
- z = Bs' * (W .* Z) * Bt ./ w;
- end
- function u = b(t,T,j,p) %calcul des splines
- i = j+1;
- if p==0
- u = (t>= T(i) & t < T(i+p+1)); return
- end
- u = zeros(size(t));
- if T(i) ~= T(i+p)
- u = u + ((t-T(i)) / (T(i+p) -T(i))) .* b(t,T,j,p-1);
- end
- if T(i+1) ~= T(i+p+1)
- u = u + ((T(i+p+1)-t) ./ (T(i+p+1) -T(i+1))) .* b(t,T,j+1,p-1);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement