Define tangent line along each boundary points of a curve

3 visualizzazioni (ultimi 30 giorni)
Dear experts, I am looking for suggestions for the problem below.
For each point at a curve, the tangent of this point is defined by the straight line that best fits (in the sense of least-squared error) a neighbourhood of p points at the curve, centred on the point of interest. My aim is to get the slope of such tangent at each curve point. Matlab function gradient won't work since our definition of "tangent" is different. Many thanks for your help.

Risposte (1)

Image Analyst
Image Analyst il 2 Ott 2014
You have to get a handful of points on the boundary around the point you want the tangent of, like say 11 points or something. Then fit to a curve, like say, a quadratic:
coefficients = polyfit(x, y, 2);
Then, from basic calculus, the slope of a quadratic a1*x^2 + a2 is 2*a1. So make up a line with that slope
slope = 2 * coefficients(1);
using the point slope formula (y-yp)= slope*(x-xp). You can just plug in two (x,y) endpoints for a line segment and use line() to display the line.

Community Treasure Hunt

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

Start Hunting!

Translated by