9 views (last 30 days)

Hi,

Can someone propose some alternate or additional code (to the code proposed in my last posting here) that will automatically connect the dots (dots = center points of each triplet), as shown below, to generate the correct polygons from the given points in the attached file (fpep.mat)?

Note 1: The edges of each polygon must be circular arcs (we cannot use splines for this one) that connect all the center points.

Note 2: Each "triplet" will produce precesely 3 circular arcs (except for those along the outer borders).

Note 3: Each arc's initial and final slopes are given by the angle between the centerpoint and the corresponding endpoint for that arc (remember that the inital and final slopes of each arc must be equal-and-opposite; so, the "starting" and "landing" angles must be averaged).

The coords of each endpoint are contained in the first 6 columns of the attached file (fpep.mat) and the coords of the center points are contained in the last two columns.

Once again, I'm excited to see what you can come up with. Thanks in advance for your help!

Matt J
on 18 Nov 2019

Edited: Matt J
on 18 Nov 2019

The spline plotting that we came up with in our previous conversation looked like this

for i=1:N

C1=AP(:,1,i); C2=AP(:,4,i); %Center points

V1=AP(:,2,i); V2=AP(:,3,i); %Triplet end points

L=norm(C2-C1);

U=(C2-C1)/L;

s=[0, dot(V1-C1,U)/L , dot(V2-C1,U)/L , 1];

APi=interp1(s.',AP(:,:,i).',sq.','spline');

X(:,i)=APi(:,1); %x coordinates on connecting curve

Y(:,i)=APi(:,2); %y coordinates on connecting curve

end

It is this section of code (and nothing else) that you need to modify to connect C1 and C2 (the center points of the i-th arc) with a different curve of your choosing.You simply must fill X(:,i) and Y(:,i) with the x and y coordinates of the points that form the desired connecting curve (based on C1,V1,V2, and C2).

Matt J
on 18 Nov 2019

You might wish to give this version a try. It is a quadratic approximation, but it is constrained to run symmetrically from C1 to C2, and with the slope constraints you have stipulated.

for i=1:N

C1=AP(:,1,i); C2=AP(:,4,i);

V1=AP(:,2,i); V2=AP(:,3,i);

L=norm(C2-C1);

U=(C2-C1)/L;

dV1=(V1-C1)/norm(V1-C1);

dV2=(V2-C2)/norm(V2-C2);

theta1=acosd(dot( dV1, U) );

theta2=acosd(dot( dV2, -U) );

theta=(theta1+theta2)/2;

W=cross( cross([U;0],[dV1;0]), [U;0]);

W=W(1:2)/norm(W);

D=L/2;

a=-tand(theta)/2/D;

t=2*D*sq;

s=polyval([a,0,-a*D^2],t);

XY=(C1+C2)/2+U*t+W(1:2)*s;

X(:,i)=XY(1,:);

Y(:,i)=XY(2,:);

end

Steven Lord
on 14 Nov 2019

Matt J
on 18 Nov 2019

Edited: Matt J
on 18 Nov 2019

I have attached a version of TripletGraph.m which implements methods of joining the points with ideal circular arcs, as well as with the spline and quadratic approximations discussed previously. The code below plots your data with circular and quadratic arcs super-imposed. To my eye, there is no visible difference, so it seems like it should be sufficient to use the quadratic approximation, which as I have said is numerically a lot safer.

load fpep

obj=TripletGraph(fpep);

figure(1);

obj.plotcirc; %join with ideal circular arc formula

hold on;

obj.plotquad; %join with quadratic approximation

hold off

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 5 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_767222

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_767222

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_768232

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_768232

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_768236

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_768236

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_768257

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_768257

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_768290

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/490852-can-someone-propose-some-code-that-will-connect-the-dots-using-circular-arcs#comment_768290

Sign in to comment.