How can I find the angle between a cubic smoothing spline and a line ?

3 views (last 30 days)
Hello everyone,
As I started my internship in researching, I started using Matlab in some much more difficult way that I used to in my school, which explain my appearance on your forum.
Here is my problem:
I need to program something which allows me to detect the contact angle of a droplet on a surface. I have already programmed a part which allows me to detect the sides of the droplet, to mark it with some markers, and to get the coordinates of each markers, Then, I used the cubic smoothing spline function in order to get an approximated curve of my sides:
sz2 = size(tabl2);
Size2 = sz2(1);
for it = 1:Size2
Xg(it) = tabl2{it}(1);
Yg(it) = -tabl2{it}(2); % Minus added because of the axis direction
end
Smooth = csaps (Xg,Yg,0.05); % Xg and Yg are basically the coordinates of the left side of my droplet.
I also used a basic polyfit in order to model the contact line.
Here is a picture of the curves I get :
The blue line is my cubic spline, which represent the side of my droplet.
The red line represents the surface, which isn't perfectly straight.
Now I need to get the contact angle between my cubic spline and my contact line, but I am stuck on it, Do you have any ideas?
Thank you very much for you help.

Accepted Answer

John D'Errico
John D'Errico on 20 Sep 2017
Edited: John D'Errico on 20 Sep 2017
You have the smoothing spline. Differentiate the spline. Compute the slope of the spline at the intersection point. You already know the slope of the straight line.
Now it is simple. You have two slopes. Use atan (or atand if you want the angle in degrees) to compute the angles of both curves, with respect to the coordinate axes. Subtract the resulting angles. The difference will be the angle between the curves at the point of intersection.
It is even easier if the straight line is a horizontal line, since then the corresponding angle you would compute is zero.
WTP?
  2 Comments
Clement Prunier
Clement Prunier on 21 Sep 2017
Hello
Thank you for your answer, but I am still a bit confused. What do you mean by compute the slope of the spline at the intersection point? I know I should try to get the slope of my derivative at the intersection point, but i can't just do
slope = deriv(x)
Because it doesn't return me the value of the derivative at this point, but instead
deriv(113)
Index exceeds matrix dimensions.
Do you know which syntax I should use to get this value?
Thank you
Clement Prunier
Clement Prunier on 22 Sep 2017
I finally found it, I'll put it for other peoples :
derivD = fnder(SmoothD,1); %Derivative of my spline
ContactD = Xd(1); %Contact point between my spline and my line
CAD = 180-(atand (fnval(derivD,ContactD))); %Contact angle between both, assuming that the contact line is a straight line // to the x axis
Thank you for your help.

Sign in to comment.

More Answers (1)

Konstantin Gulin
Konstantin Gulin on 19 Sep 2017
I would recommend finding the contact vectors for your two curves.
For the spline, take two points; the point of contact [x2 y2] and the point immediately preceding that one [x1 y1].
Generate the vector (you need to add a third dimension, even if it's irrelevant):
v = [(x2 - x1) (y2-y1) 0]
Do the same thing for your line and generate a vector u.
To find the angle between the two use:
Theta = atan2d(norm(cross(u,v)),dot(u,v));
  3 Comments
Konstantin Gulin
Konstantin Gulin on 20 Sep 2017
You can use the Y values from your spline function. For example if your spline is:
s = spline(x,y,xq)
then s(x) will return all the y values in your spline function.
Clement Prunier
Clement Prunier on 21 Sep 2017
Unfortunatly, this syntax doesn't work for the kind of function I have. I used the csaps function, but I don't understand what kind of function it gives me and how to get values from it. Do you have any idea?
Thank you for your help

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!