15,512,502 members
1.00/5 (1 vote)
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.

```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')```
Posted
Amarnath S 7-Apr-22 2:47am
What are your expected results?
thisisjinesh 7-Apr-22 4:55am
The surface need to get created from the Bezier curve and the 4 points of the curve should still remain same which is not happing in the code which I have shared. There might be some mistake which I am not able to figure out.
Amarnath S 7-Apr-22 6:20am
At a first glance, it looks like this line is incorrect

(((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
thisisjinesh 7-Apr-22 12:18pm
Hi sir,
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.
thisisjinesh 7-Apr-22 12:21pm
I also tried equations from books. It shows the basic concept of generating 2 surfaces from 4 curves and then deducting correction surface. Books mention S = S1 + S2 -S3 where S is the final surface and S1, S2 are the surface generated from the Bezier curve and S3 is the correction surface to keep all 4 points on one plane. I tried this equation but it was not giving curved surface at all so I got confused further.

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

Top Experts
Last 24hrsThis month
 OriginalGriff 195 Richard MacCutchan 100 Graeme_Grant 100 Richard Deeming 85 Dave Kreskowiak 50
 OriginalGriff 1,134 Richard Deeming 893 Richard MacCutchan 851 Dave Kreskowiak 260 merano99 195

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