15,845,785 members

See more:

I have following data from which I need to create coon's patch.

I need to code in Matlab

Matrix of polygon vertices given below

P0u = [0,0,0; 0.2357,0.2357,0.3333; 1.1785,0.2357,0.3333; 1.4142,0,0];

P0w = [1.4142,0,0; 1.1785,0.2357,0.3333; 1.1785,1.1785,0.3333; 1.4142,1.4142,0];

P1u = [1.4142,1.4142,0; 1.1785,1.1785,0.3333; 0.2357,1.1785,0.3333; 0,1.4142,0];

P1w = [0,1.4142,0; 0.2357,1.1785,0.3333; 0.2357,0.2357,0.3333; 0,0,0];

**What I have tried:**

I have tried below Matlab code but it is not giving appropriate results.

I need to code in Matlab

Matrix of polygon vertices given below

P0u = [0,0,0; 0.2357,0.2357,0.3333; 1.1785,0.2357,0.3333; 1.4142,0,0];

P0w = [1.4142,0,0; 1.1785,0.2357,0.3333; 1.1785,1.1785,0.3333; 1.4142,1.4142,0];

P1u = [1.4142,1.4142,0; 1.1785,1.1785,0.3333; 0.2357,1.1785,0.3333; 0,1.4142,0];

P1w = [0,1.4142,0; 0.2357,1.1785,0.3333; 0.2357,0.2357,0.3333; 0,0,0];

I have tried below Matlab code but it is not giving appropriate results.

clc clear close all %% Defining input parameters % Defining individual point on polygon A1 = [0,0,0]; A2 = [0.2357,0.2357,0.3333]; A3 = [1.1785,0.2357,0.3333]; A4 = [1.4142,0,0]; B1 = [1.4142,0,0]; B2 = [1.1785,0.2357,0.3333]; B3 = [1.1785,1.1785,0.3333]; B4 = [1.4142,1.4142,0]; C1 = [1.4142,1.4142,0]; C2 = [1.1785,1.1785,0.3333]; C3 = [0.2357,1.1785,0.3333]; C4 = [0,1.4142,0]; D1 = [0,1.4142,0]; D2 = [0.2357,1.1785,0.3333]; D3 = [0.2357,0.2357,0.3333]; D4 = [0,0,0]; %% Plot polygon P0u = [A1;A2;A3;A4]; % Creating matrix for polygon vertices P0w = [B1;B2;B3;B4]; % Creating matrix for polygon vertices P1u = [C1;C2;C3;C4]; % Creating matrix for polygon vertices P1w = [D1;D2;D3;D4]; % Creating matrix for polygon vertices [r,s] = size(P0u); % getting size of matrix in terms of rows and columns [r,s] = size(P0w); % getting size of matrix in terms of rows and columns [r,s] = size(P1u); % getting size of matrix in terms of rows and columns [r,s] = size(P1w); % getting size of matrix in terms of rows and columns n = r-1; % n+1 represents number of vertices of the polygon np = 20; % represents number of equi-distance points on the bezier curve t = linspace(0,1,np); hold all grid on view(45,45) figure(1) xlabel('X-Axis') ylabel('Y-Axis') zlabel('Z-Axis') for k = 1:n plot3([P0u(k,1),P0u(k+1,1)], [P0u(k,2),P0u(k+1,2)], [P0u(k,3),P0u(k+1,3)], 'r', 'LineWidth', 1); plot3([P0w(k,1),P0w(k+1,1)], [P0w(k,2),P0w(k+1,2)], [P0w(k,3),P0w(k+1,3)], 'r', 'LineWidth', 1); plot3([P1u(k,1),P1u(k+1,1)], [P1u(k,2),P1u(k+1,2)], [P1u(k,3),P1u(k+1,3)], 'r', 'LineWidth', 1); plot3([P1w(k,1),P1w(k+1,1)], [P1w(k,2),P1w(k+1,2)], [P1w(k,3),P1w(k+1,3)], 'r', 'LineWidth', 1); end %% Generate the points on the bezier curve for j = 1:np P1 = [0,0,0]; P2 = [0,0,0]; P3 = [0,0,0]; P4 = [0,0,0]; for i = 0:n M(i+1) = (factorial(n)/(factorial(i)*factorial(n-i)))*((t(j))^i)*((1-t(j))^(n-i)); P1 = P1 + P0u(i+1,:).*M(i+1); P2 = P2 + P0w(i+1,:).*M(i+1); P3 = P3 + P1u(i+1,:).*M(i+1); P4 = P4 + P1w(i+1,:).*M(i+1); end Q1(j,:) = P1; Q2(j,:) = P2; Q3(j,:) = P3; Q4(j,:) = P4; end %% Plot the bezier curve from the obtained points for l = 1:np-1 plot3([Q1(l,1),Q1(l+1,1)],[Q1(l,2),Q1(l+1,2)], [Q1(l,3),Q1(l+1,3)], 'b', 'LineWidth', 1); plot3([Q2(l,1),Q2(l+1,1)],[Q2(l,2),Q2(l+1,2)], [Q2(l,3),Q2(l+1,3)], 'b', 'LineWidth', 1); plot3([Q3(l,1),Q3(l+1,1)],[Q3(l,2),Q3(l+1,2)], [Q3(l,3),Q3(l+1,3)], 'b', 'LineWidth', 1); plot3([Q4(l,1),Q4(l+1,1)],[Q4(l,2),Q4(l+1,2)], [Q4(l,3),Q4(l+1,3)], 'b', 'LineWidth', 1); end %% Bilinear surface npu = 10; % Number of points in u-direction npw = 10; % Number of points in w-direction u = linspace(0,1,npu); w = linspace(0,1,npw); for i = 1:npu for j = 1:npw Q = (((1-u(i))^3*A1)+(A2*3*u(i)*(1-u(i))^2)+(A3*3*u(i)^2*(1-u(i)))+(A4*u(i)^3))*(1-w(j)) + ... (((1-u(i))^3*C1)+(C2*3*u(i)*(1-u(i))^2)+(C3*3*u(i)^2*(1-u(i)))+(C4*u(i)^3))*(w(j)) + ... (((1-w(j))^3*B1)+(B2*3*w(j)*(1-w(j))^2)+(B3*3*w(j)^2*(1-w(j)))+(B4*w(j)^3))*(1-u(i))+... (((1-w(j))^3*D1)+(D2*3*w(j)*(1-w(j))^2)+(D3*3*w(j)^2*(1-w(j)))+(D4*w(j)^3))*(u(i)) - ... (((1-u(i)*(1-w(j))* A1))) - (((1-u(i)*(w(j))* C1))) - (((1-w(j)*(u(i))*D1))) - (((w(j)*(u(i))* B4))); Qx(i,j) = Q(1); Qy(i,j) = Q(2); Qz(i,j) = Q(3); end end surf(Qx,Qy,Qz) xlabel('X-Axis') ylabel('Y-Axis') zlabel('Z-Axis')

Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

(((1-u(i)*(1-w(j))* A1))) - (((1-u(i)*(w(j))* C1))) - (((1-w(j)*(u(i))*D1))) - (((w(j)*(u(i))* B4)));

A4,

You have A1, C1, D1 and B4. Should they all not have the same index - All should be A1, C1, D1, B1, or all should be A4, etc.

If you have any reference to the formula for the Coons surface, check the coefficients one by one. In my reference, I have a different formula for the Coons surface, as shown in one of my articles - https://www.codeproject.com/Articles/5295155/CurSur-3D-Curves-and-Surfaces-in-Geometric-Design

Thanks for your reply.

I have checked your suggestion but still it is not showing the expected results.

I have gone through your article.

Section 11 of your article "Gallery" is showing one surface named Canopy. That's how the expected result on the same curve.

But in my code of course something wrong there which I am not able to figure out still. the surface is getting generated far away from the original Bezier curve and not showing expected results.

In your article you have mentioned about bicubic coons patch, however, I was looking for bilinear coon's patch. I am sorry for inconvenience if I did not mention this earlier in the question.

If you send me a link to the formulas, I will find some time to work on it tomorrow afternoon (India time).

Once again thanks a lot for your guidance and help.

the equation in book is

Q(u, w) = P(u, 0)(1 — w) + P(u, 1)w + P(0,w)(1 — u) + P(1, w)u

— P(O, 0)(1 — u)(1 — w) — P(O, 1)(1 — u)w

— P(1, 0)u(1 — w) — P(1, 1)uw

in above equation I tried two things.

For first part of equation I used P0u, P0w, P1u and P1w as it is and also tried Q1, Q2, Q3, Q4 which are my bezier curve but both way only plain surface at some angle is getting created.