finding the area of a closed 2d uniform cubic B-spline

余生长醉 提交于 2019-12-04 01:33:55
  1. Pick some arbitrary point as pivot p0 (e.g. the origin (0,0))
  2. Pick some point along the curve p1 = (x,y)
  3. Differentiate the curve at that point, to get a velocity v = <vx,vy>
  4. Form a triangle from the three points, and calculate the area. Easiest done with a cross product between the vectors p0p1 and v, and dividing by two.
  5. Integrate this area over t, from 0 to 1.

The result you get is the area for one segment of the whole curve. Some will be negative, as they face the opposite direction. If you sum up the areas for all segments, you get the area of the whole curve.

The result is:

Areai = (31 xi-1yi + 28 xi-1yi+1 + xi-1yi+2 - 31 xiyi-1 + 183 xiyi+1 + 28 xiyi+2 - 28 xi+1yi-1 - 183 xi+1yi + 31 xi+1yi+2 - xi+2yi-1 - 28 xi+2yi - 31 xi+2yi+1) / 720

If you convert it into matrix form, you get:

Areai = <xi-1   xi   xi+1   xi+2> · P · <yi-1   yi   yi+1   yi+2>T

where P is

[    0   31   28    1]
[  -31    0  183   28] / 720
[  -28 -183    0   31]
[   -1  -28  -31    0]

If the control points are [(0,0) (1,0) (1,1) (0,1)], the resulting areas become:

[(0,0), (1,0), (1,1), (0,1)] -> 242/720
[(1,0), (1,1), (0,1), (0,0)] -> 242/720
[(1,1), (0,1), (0,0), (1,0)] ->   2/720
[(0,1), (0,0), (1,0), (1,1)] ->   2/720

The sum is 488/720 = 61/90.

Personally, I would use the splines to their best advantage and rewrite the area integral as a contour integral using Green's theorem.

Since you already know the curve, it'll be an easy matter to do the integration using Gaussian quadrature of sufficient order. No shenanigans to estimate the extra areas needed. I'll bet it'll be computationally efficient as well, because Gaussian quadrature over polynomials is so well behaved. Cubic B-splines will integrate nicely.

I would write your code in such a way that the first and last points must be coincident. That's an invariant on the problem.

This approach will even work for areas with holes in them. You integrate along the outer curve, make an imaginary straight line that connects the outer to the inner curve, integrate along the inner curve, then pass back to the outer along the straight line that got you there.

BlacKow

Well... it looks like you already know what to do.

  1. Yes, this is correct way of calculating area under the segment, indeed

    dS=Y*dX=Y*(dX/dt)*dt
    
  2. You don't need to care about adding or subtracting. You need to add all the time, but some of the integrals (red segments) will be negative (if you always set put your Pn in the beginning of coordinates and Pn+1 along X axis positive direction). So for every segment you need to calculate translation and rotation and then integral (all done analytically).

  3. I don't know about Python module, but it seems that making such a module will take a day at most.
  4. I think analytic solution will be better and is not so hard.

Anyway the graphics is absolutely stunning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!