Tangent part of a parametric discrete curve

I have a parametric curve, say, two doubling vectors, where the parameter is the index, and I must calculate the angle of the tangent to this curve at any given point (index).

Any suggestion or link on how to do this?

Thank.

+3
source share
6 answers

The tangent to a smooth curve at the point P is the parametric line P + tV, where V is the derivative of the curve with respect to the “parameter”. But here the parameter is just an index of the array, and numerical differentiation is a difficult task, therefore, to approximate the tangent, I would use the (weighted) least squares approximation .

In other words, select three or five points of the curve around your point of interest P (ie, P [i-2], P [i-1], P [i], P [i + 1] and P [i + 2 ], if P == P [i]) and approximate their line, in the sense of least squares. The more weight you assign to the midpoint P, the closer the line will be to P; on the other hand, the more weight you assign to extreme points, the more “tangent” the straight line will be, i.e. the more beautiful it will bring you closer to the curve in the neighborhood of point P.

For example, regarding the following points:

x = [-1, 0, 1]
y = [ 0, 1, 0]

for which the tangent is not defined (as in Anders Abel's answer), this approach should give a horizontal line close to the point (0,1).

+1
source

Here is a short formula equivalent to (I think) the answer of pau.estalella:

m[i] = (y[i+1] - y[i-1]) / (x[i+1] - x[i-1])

(x[i], y[i]).

" ". , m[i], arctangent(m[i]) arctangent(m[i]) x. , , , :

angle[i] = atan2(y[i+1] - y[i-1], x[i+1] - x[i-1])

, x[i+1] == x[i-1].

+6

, , , . , , :

x = { 1.0, 2.0, 2.0 };
y = { 1.0, 1.0, 2.0 };

90- . .

gregseth

, "" , (P0, P2), P1... : N (N-1, N + 1), N. ?
, . , :

x = { 1.0, 2.0, 2.0 };
y = { 1.0, 1000000, 1000000 };

L- . , . , , 45 ? , .

, , . , 45- .

+3

. , , , , , .

+3

: dy/dx. .

+2

, ( , ) .

C p1, p2 p3. p2 : t1 = p2-p1 t2 = p3-p2. , : 0.5 * (t1 + t2)   ( 1/).

.

To calculate the angle between the tangent and the curve, remember that the point product of two unit vectors gives the cosine of the angle between them. Take the resulting tangent t and the unit vector v2 = | p3-p2 |, and acos (dot (t, v2)) sets the required angle.

0
source

Source: https://habr.com/ru/post/1739301/


All Articles