简体   繁体   中英

how to calculate arc length of the arc consisting of 3D points in opencv using python?

I have a curve sampled using discrete points. It is not a closed curve. I want to calculate the arc length. In opencv the arclength function takes 2D points.

Any ideas?

Thanks a lot

Bear in mind that taking discrete points this will be an estimate, but a rough method to calculate the arc length is to simply sum the distances/magnitudes between subsequent points. So if x is the ordered list of sampled 2D points on the closed curve:

sum( magnitude(x[i]-x[i+1]) for i in range(len(points)-1) )

If you know some other properties about the curve, you may be able to calculate this more accurately...

.

The same technique can be applied to vectors of higher dimension, where you can use the generalised formula:

def dist(X,Y):
    return math.sqrt(
                     sum( (X[i] - Y[i])**2 for i in len(range(X)) )
                    )

sum( dist(x[i],x[i+1]) for i in range(len(points)-1) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM