curvey.curve¤
Curve
¤
A discrete planar closed curve
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pts |
PointsLike
|
|
required |
**kwargs |
Metadata parameters in key=value format. |
{}
|
Source code in src\curvey\curve.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 |
|
Constructors¤
circle(n: int, r: float = 1.0) -> Self
classmethod
¤
Construct a regular polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
Number of vertices. |
required |
r |
float
|
The radius. |
1.0
|
Source code in src\curvey\curve.py
dumbbell(n: int, rx: float = 2, ry: float = 2, neck: float = 0.2) -> Self
classmethod
¤
Construct a dumbbell shape
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
Number of points |
required |
rx |
float
|
Width parameter |
2
|
ry |
float
|
Height parameter |
2
|
neck |
float
|
Height of the pinched neck |
0.2
|
Source code in src\curvey\curve.py
ellipse(n: int, ra: float, rb: float) -> Self
classmethod
¤
Construct an ellipse
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
Number of vertices. |
required |
ra |
float
|
Major radius. |
required |
rb |
float
|
Minor radius. |
required |
Source code in src\curvey\curve.py
from_curvature(curvature: ndarray, edge_lengths: ndarray, solve_vertices: bool = True, theta0: float | None = None, pt0: ndarray | Sequence[float] | None = None, dual_edge_lengths: ndarray | None = None, laplacian: ndarray | scipy.sparse.base.spmatrix | None = None) -> Self
classmethod
¤
Construct a curve with the supplied new curvatures and edge lengths
As explained in
Robust Fairing via Conformal Curvature Flow. Keenan Crane, Ulrich Pinkall, and Peter Schröder. 2014
The product (curvature * edge_lengths) is integrated to obtain tangent vectors, and then
tangent vectors are integrated to obtain vertex positions. This reconstructs the curve
up to rotation and translation. Supply theta0
and pt0
to fix the orientation of the
first edge and the location of the first point.
This may result in an improperly closed curve. If solve_vertices
is True, vertex
positions are found by a linear projection to the closest closed curve, as described
in Crane et al.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curvature |
ndarray
|
A length |
required |
edge_lengths |
ndarray
|
A length |
required |
theta0 |
float | None
|
The constant of integration defining the angle of the first edge and the x-axis, in radians. |
None
|
pt0 |
ndarray | Sequence[float] | None
|
A 2-element array. The constant of integration defining the absolute position of the first vertex. |
None
|
solve_vertices |
bool
|
If True, length discretization errors are resolved by solving ∆f = ▽ · T as the discrete Poisson equation Lf = b for the vertex positions f, as per Crane §5.2. Otherwise, vertex positions are found by simply integrating tangent vectors, which may result in an improperly closed contour. |
True
|
laplacian |
ndarray | spmatrix | None
|
The |
None
|
dual_edge_lengths |
ndarray | None
|
The length |
None
|
Examples:
Construct a circle from its expected intrinsic parameters.
import numpy as np
from curvey import Curve
n = 20
curvatures = np.ones(n)
edge_lengths = 2 * np.pi / n * np.ones(n)
c = Curve.from_curvature(curvatures, edge_lengths)
_ = c.plot_edges()
Construct a circle from noisy parameters, using solve_vertices
to ensure the curve
is closed.
curvatures = np.random.normal(1, 0.1, n)
edge_lengths = 2 * np.pi / n * np.random.normal(1, 0.1, n)
c0 = Curve.from_curvature(curvatures, edge_lengths, solve_vertices=False)
c1 = Curve.from_curvature(curvatures, edge_lengths, solve_vertices=True)
_ = c0.plot(color='black')
_ = c1.plot(color='red')
Source code in src\curvey\curve.py
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 |
|
star(n: int, r0: float, r1: float) -> Self
classmethod
¤
Construct a (isotoxal) star polygon with n
corner vertices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
The number of corner vertices. The returned curve has |
required |
r0 |
float
|
Radius of the even vertices. |
required |
r1 |
float
|
Radius of the odd vertices. |
required |
Source code in src\curvey\curve.py
Curve-valued properties¤
area: float
cached
property
¤
Absolute area of the polygon enclosed by the curve
center: ndarray
cached
property
¤
The average vertex position
centroid: ndarray
cached
property
¤
The center of mass of the uniformly weighted polygon enclosed by the curve
data: MappingProxyType[str, Any]
property
¤
A read-only view of the curve's metadata
is_simple: bool
cached
property
¤
False if the curve intersects or touches itself, including having repeated points
Uses shapely.LinearRing.is_simple
laplacian: scipy.sparse.dia_matrix
cached
property
¤
The discrete Laplacian
The Laplacian here is the graph Laplacian of a weighted graph with edge weights \(1 / d_{i, j}\), where \(d_{i, j}\) is the distance (edge length) between adjacent vertices \(i\) and \(j\).
Returns a sparse matrix \(L\) of size (n, n)
with diagonal entries
and off-diagonal entries
\(\(L_{i,j} = -1 / d_{i, j}\)\).
length: float
cached
property
¤
Total arclength; the sum of edge lengths
n: int
property
¤
The number of vertices
(or the number of edges, since this is a closed curve)
orientation: int
cached
property
¤
Orientation of the curve
Integer-valued; +1
if curve is oriented counterclockwise, -1
if clockwise, 0 if zero
area
signed_area: float
cached
property
¤
Signed area of the polygon enclosed by the curve
Signed area is positive if the curve is oriented counter-clockwise.
Calculated by the shoelace formula.
Vertex-valued properties¤
The following properties have length n
:
arclength: ndarray
property
¤
Vertex arclengths
arclength
is a length n
vector, where arclength[i]
is the arclength
of the i
th vertex. arclength[0]
is always zero. arclength[i]
for i>0
is equal to
`cum_edge_length[i-1].
See also
Curve.closed_arclength
Like arclength
, but also includes self.length
as the final element.
curvature: ndarray
cached
property
¤
Length n
vector of signed vertex curvatures
Computed as $$ \kappa_i = \frac {2 \psi_i}{L_{i-1, i} + L_{i, i+1}} $$ Where \(\psi_i\) is the turning angle between the two edges adjacent to vertex \(i\), and \(L_{ij}\) is the length of the edge between vertex \(i\) and \(j\).
Note
There are multiple ways to reasonably define discrete curvature. (See Table 1 in
Vouga 2014 for a summary of their tradeoffs.) One is chosen here for
convenience; most of the curvature flows in curvey.flow
accept a curvature_fn
to allow
this choice to be overridden.
dual_edge_length: ndarray
cached
property
¤
Vertex dual edge lengths
curve.dual_edge_length[i]
is the average length of the two edges incident on vertex \(i\),
i.e. \((L_{i-1, i} + L_{i, i+1})/2\) where \(L_{ij}\) is the edge length between vertex
\(i\) and vertex \(j\).
normal: ndarray
cached
property
¤
Vertex unit normal vectors
Normals are computed by rotating the unit tangents 90 degrees counter-clockwise, so that \(\left[ T_i, N_i, 1 \right]\) forms a right-handed frame at vertex \(i\) with tangent \(T_i\) and normal \(N_i\).
For a counter-clockwise-oriented curve, this means that normals point inwards.
See also
Curve.edge_normal The exact unit normals for each edge.
points: ndarray
cached
property
¤
A (n, 2)
array of curve vertex coordinates
tangent: ndarray
cached
property
¤
Unit length tangent vectors
tangent[i]
is the curve unit tangent vector at vertex i
. This is constructed from
second order finite differences; use Curve.unit_edge
for the exact vector from
vertex i
to vertex i+1
.
turning_angle: ndarray
cached
property
¤
Turning angle (a.k.a exterior angle), in radians between adjacent edges
curve.turning_angle[i]
is the angle between the vectors \(T_{i-1, i}\) and \(T_{i, i+1}\)
where \(T_{ij}\) is the vector from vertex \(i\) to vertex \(j\).
Angles are in the range \(\pm \pi\).
x: ndarray
property
¤
The x-component of the curve vertices
y: ndarray
property
¤
The y-component of the curve vertices
Vertex + 1 -valued properties¤
These are special cases and have length n + 1
closed_arclength: ndarray
property
¤
Cumulative edge lengths with zero prepended
closed_arclength
is a length n+1
vector, where the first element is 0
, the
second element is the length of the first edge, and the last element is the cumulative
length of all edges, curve.length
.
closed_points: ndarray
property
¤
A (n+1, 2)
array of the vertex coordinates where the last row is equal to the first
Curvey uses an implicitly closed representation, assuming an edge exists between the last
and first point, i.e. in general curve.points[0] != curve.points[-1]
. Sometimes
it's useful to have an explicit representation.
Edge-valued properties¤
The following properties have length n
:
cum_edge_length: ndarray
cached
property
¤
Cumulative edge lengths
Simply equal to np.cumsum(self.edge_length)
.
cum_edge_length
is a length n
vector, and does not include zero,
i.e. curve.cum_edge_lengths[0]
is the length of the first edge, and
curve.cum_edge_length[-1]
== curve.length
.
See also
Curve.arclength
Vertex arclength, like cum_edge_length
but starts at 0.
edge: ndarray
cached
property
¤
The vectors from vertex i
to i+1
See also
Curve.unit_edge For unit edge vectors.
edge_length: ndarray
cached
property
¤
Curve edge lengths
edge_length[i]
is the length of the edge from vertex i
to vertex i+1
.
See also
Curve.cum_edge_length Cumulative egde lengths.
edge_normal: ndarray
cached
property
¤
Unit edge normals
edge_normal[i]
is the unit vector normal to the edge from vertex i
to i+1
.
Normals are computed by rotating the unit edge vectors 90 degrees counter-clockwise.
For a counter-clockwise-oriented curve, this means that normals point inwards.
See also
Curve.normal Vertex normals calculated from 2nd order finite differences.
edges: ndarray
property
¤
A (n, 2)
array of vertex indices
The integer valued vertex connectivity array [(0, 1), (1, 2), ..., (n-2, n-1), (n-1, 0)]
.
unit_edge: ndarray
cached
property
¤
The unit edge vectors from vertex i
to i+1
See also
Curve.tangent For unit tangent vectors calculated from second-order finite differences.
Transformations¤
All transformations return a new Curve
; nothing modifies a Curve
inplace.
Basic transformations¤
with_points(pts: ndarray) -> Curve
¤
A curve with the newly supplied points array, but same metadata values
Source code in src\curvey\curve.py
with_data(**kwargs) -> Curve
¤
A new curve with the same points and metadata appended with the supplied metadata
E.g. curve.with_data(foo=1, bar=2).with_data(baz=3)
has metadata parameters
'foo', 'bar', and 'baz'.
This allows without complaint overwriting previous metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
New metadata in key=value format |
{}
|
Source code in src\curvey\curve.py
drop_data(*args: str) -> Curve
¤
Copy of the curve without the listed metadata parameters
Use curve.drop_data(*curve.data.keys())
to drop all data.
Source code in src\curvey\curve.py
reverse(keep_first=False) -> Curve
¤
Reverse the curve orientation
Flips between clockwise and counter-clockwise orientation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep_first |
By default, the list of vertices is simply flipped. This changes which point is first.
If |
False
|
Source code in src\curvey\curve.py
scale(scale: float) -> Curve
¤
translate(offset: ndarray | Literal['center', 'centroid']) -> Curve
¤
Translate the curve
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
ndarray | Literal['center', 'centroid']
|
One of
- A 2 element vector |
required |
Source code in src\curvey\curve.py
roll(shift: int) -> Curve
¤
Circular permutation of the vertex order
To make vertex i
the first vertex, use curve.roll(-i)
.
rotate(theta: float) -> Curve
¤
Rotate the curve about the origin
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
float
|
Angle in radians to rotate the curve. Positive angles are counter-clockwise. |
required |
Source code in src\curvey\curve.py
reflect(theta: float | Literal['x', 'X', 'y', 'Y']) -> Curve
¤
Reflect the curve over a line through the origin
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
float | Literal['x', 'X', 'y', 'Y']
|
Angle in radians of the reflection line through the origin.
If |
required |
Source code in src\curvey\curve.py
to_cw() -> Curve
¤
to_ccw() -> Curve
¤
transform(transform: ndarray) -> Curve
¤
Apply a 2x2 or 3x3 transform matrix to the vertex positions
Source code in src\curvey\curve.py
to_area(area: float = 1.0) -> Curve
¤
to_edge_midpoints() -> Curve
¤
The curve whose vertices are the midpoints of this curve's edges
Mostly just useful for plotting scalar quantities on edge midpoints.
Source code in src\curvey\curve.py
to_length(length: float = 1.0) -> Curve
¤
to_orientation(orientation: int) -> Curve
¤
A curve with the specified orientation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
orientation |
int
|
Must be either |
required |
Source code in src\curvey\curve.py
Sampling transformations¤
collapse_shortest_edges(n: int | None = None, min_edge_length: float | None = None) -> Curve
¤
Remove vertices belonging to the shortest edges until a stopping criterion is met
Note
No attempt is made to prevent self-intersection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int | None
|
Stop after collapsing this many edges. |
None
|
min_edge_length |
float | None
|
Stop when the shortest edge is longer than this. |
None
|
Source code in src\curvey\curve.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 |
|
interpolate(s: ndarray, typ: InterpType = 'cubic') -> Curve
¤
Construct a new curve by interpolating vertex coordinates at the supplied arclengths
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
ndarray
|
Arclength values to interpolate at. |
required |
typ |
InterpType
|
Type of interpolation, one of ('linear', 'cubic', 'pchip'). |
'cubic'
|
Source code in src\curvey\curve.py
split_edges(n: ndarray) -> Curve
¤
Sample uniformly within edge segments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
ndarray
|
A integer-valued vector of length When When When When |
required |
Returns:
Type | Description |
---|---|
Curve
|
A curve with |
Source code in src\curvey\curve.py
split_longest_edges(n: int) -> Curve
¤
Insert n
new vertices by uniform edge subdivision
Edges are split in priority of their length, so very long edges may be split into thirds, fourths, etc. before very short edges are split in half.
Source code in src\curvey\curve.py
subdivide(n: int = 1) -> Curve
¤
Create a new curve by evenly subdividing each edge
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
Number of new points to add to each edge. For |
1
|
Source code in src\curvey\curve.py
Target transformations¤
These transformations accept an additional target curve.
align_to(target: Curve, *, return_transform: bool = False) -> Curve | ndarray
¤
Align to another curve by removing mean change in position and edge orientation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Curve
|
The target curve to align to. It must have the same number of vertices as |
required |
return_transform |
bool
|
If true, return the 3x3 transformation matrix. Otherwise, return a |
False
|
See also
Curve.register_to Iterative closest point registration, which doesn't require corresponding vertices.
Source code in src\curvey\curve.py
optimize_edge_lengths_to(other: Curve, interp_typ: InterpType = 'cubic') -> Curve
¤
Optimize partitioning of vertex arclength positions to match edge_lengths in other
self
and other
must have the same number of vertices.
This assumes self
and other
have already been processed to have the same length!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Curve
|
The curve to optimize against |
required |
interp_typ |
InterpType
|
Passed to |
'cubic'
|
Source code in src\curvey\curve.py
orient_to(other: Curve) -> Curve
¤
register_to(target: Curve, allow_scale: bool = False, return_transform=False) -> Curve | ndarray
¤
Iterative closest point registration
Minimizes
where \(d(v_i, e_j)\) is the euclidean distance btween vertices \(v_i\) in self
and edges \(e_j\) in target
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Curve
|
The |
required |
allow_scale |
bool
|
If True, allow uniform scaling. |
False
|
return_transform |
If True, return a 3x3 transform matrix. Otherwise, return the transformed |
False
|
See also
Curve.align_to
When source
and target
have the same number of vertices in 1-to-1 correspondance.
Source code in src\curvey\curve.py
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 |
|
roll_to(other: Curve) -> Curve
¤
Cyclicly permute points to minimize the distance between corresponding points
other
must have the same number of vertices as self
Source code in src\curvey\curve.py
Plotting¤
plot(color='black', ax: Axes | None = None, **kwargs) -> Line2D
¤
Plot the curve as a closed contour
For more sophisticated plotting see methods plot_points
, plot_edges
, and plot_vectors
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color |
A matplotlib colorlike. |
'black'
|
|
ax |
Axes | None
|
Defaults to the current axes. |
None
|
**kwargs |
additional kwargs passed to |
{}
|
Source code in src\curvey\curve.py
plot_edges(color: ndarray | None = None, directed: bool = True, width: float | ndarray | None = None, scale_width: tuple[float, float] | None = None, ax: Axes | None = None, **kwargs) -> Quiver | LineCollection
¤
Plot a scalar quantity on curve edges
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color |
ndarray | None
|
The color to plot each edge. Defaults to curve arc length. |
None
|
directed |
bool
|
If True, plot edges as arrows between vertices. Otherwise, edges are line segments. |
True
|
width |
float | ndarray | None
|
The thickness of each edge segment, scalar or edge quantity vector. |
None
|
scale_width |
tuple[float, float] | None
|
Min and max widths to scale the edge quantity to. |
None
|
ax |
Axes | None
|
The matplotlib axes to plot in. Defaults to current axes. |
None
|
**kwargs |
Aadditional kwargs passed to |
{}
|
Returns:
Type | Description |
---|---|
Quiver
|
If |
LineCollection
|
If |
Source code in src\curvey\curve.py
plot_points(color: ndarray | Any | None = None, size: ndarray | float | None = None, scale_sz: tuple[float, float] | None = None, ax: Axes | None = None, **kwargs) -> PathCollection
¤
Plot a scalar quantity on curve vertices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color |
ndarray | Any | None
|
Either a matplotlib scalar colorlike or length |
None
|
size |
ndarray | float | None
|
Length |
None
|
scale_sz |
tuple[float, float] | None
|
Min and max sizes to scale the vertex quantity |
None
|
ax |
Axes | None
|
Matplotlib axes to plot in. Defaults to the current axes. |
None
|
**kwargs |
additional kwargs passed to |
{}
|
Source code in src\curvey\curve.py
plot_vectors(vectors: ndarray | None = None, scale: ndarray | None = None, color=None, scale_length: tuple[float, float] | None = None, ax: Axes | None = None, **kwargs) -> Quiver
¤
Plot vector quantities on curve vertices
To plot vector quantities on edges use curve.to_edge_midpoints.plot_vectors(...)
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vectors |
ndarray | None
|
A |
None
|
scale |
ndarray | None
|
A length |
None
|
color |
Length |
None
|
|
scale_length |
tuple[float, float] | None
|
Limits to scale vector length to, after applying |
None
|
ax |
Axes | None
|
The axes to plot in. Defaults to the current axes. |
None
|
**kwargs |
additional kwargs passed to |
{}
|
Source code in src\curvey\curve.py
Special¤
check_same_n_vertices(other: Curve) -> int
¤
Raises a ValueError
if vertex counts don't match
Otherwise, returns the common vertex count.
Source code in src\curvey\curve.py
deriv(f: ndarray | None = None) -> ndarray
¤
Second order finite differences approximations of arclength-parametrized derivatives
Derivatives are calculated by circularly padding the arclength s
and function values
f(s)
, passing those to numpy.gradient
to calculate second order finite differences,
and then dropping the padded values.
f
is the function values to derivate. By default, this is the curve points, so
curve.deriv()
computes the curve tangent. Repeated application will compute the second
derivative, e.g.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
ndarray | None
|
The |
None
|
Returns:
Name | Type | Description |
---|---|---|
deriv |
ndarray
|
The |
Source code in src\curvey\curve.py
edge_intersections() -> ndarray
¤
An (n_intersect, 2)
array of points where two edges cross
This does not include two co-incident vertices or an edge coincident on a non-adjacent vertex.
Source code in src\curvey\curve.py
interpolator(typ: InterpType = 'cubic', f: ndarray | None = None) -> Callable[[ndarray], ndarray]
¤
Construct a function interpolator on curve arclength
Parameters:
Name | Type | Description | Default |
---|---|---|---|
typ |
InterpType
|
The class of spline to use for interpolation. One of 'linear', 'cubic', or 'pchip'. |
'cubic'
|
f |
ndarray | None
|
The (n_verts,) or (n_verts, ndim) array of function values to interpolate. By default, this is just the vertex positions. |
None
|
Returns:
Name | Type | Description |
---|---|---|
interpolator |
Callable[[ndarray], ndarray]
|
A function g(s) |
Source code in src\curvey\curve.py
to_edges() -> Edges
¤
Type conversion¤
from_shapely(ring: shapely.LinearRing) -> Self
classmethod
¤
Convert a shapely.LinearRing
to a curvey.Curve
Source code in src\curvey\curve.py
to_edges() -> Edges
¤
to_matplotlib() -> matplotlib.path.Path
¤
Convert to a matplotlib.path.Path
object
Source code in src\curvey\curve.py
to_shapely(mode: Literal['ring', 'edges', 'polygon', 'points'] = 'ring')
¤
Convenience converter to shapely
object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
Literal['ring', 'edges', 'polygon', 'points']
|
Which type of
|
'ring'
|