-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add WarpBatch - array process warp with single callback
- Loading branch information
Showing
9 changed files
with
229 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# %% | ||
import numpy as np | ||
from manifold3d import * | ||
|
||
# Creates a classic torus knot, defined as a string wrapping periodically | ||
# around the surface of an imaginary donut. If p and q have a common | ||
# factor then you will get multiple separate, interwoven knots. This is | ||
# an example of using the warp() method, thus avoiding any direct | ||
# handling of triangles. | ||
|
||
|
||
def run(): | ||
# The number of times the thread passes through the donut hole. | ||
p = 1 | ||
# The number of times the thread circles the donut. | ||
q = 3 | ||
# Radius of the interior of the imaginary donut. | ||
majorRadius = 25 | ||
# Radius of the small cross-section of the imaginary donut. | ||
minorRadius = 10 | ||
# Radius of the small cross-section of the actual object. | ||
threadRadius = 3.75 | ||
# Number of linear segments making up the threadRadius circle. Default is | ||
# getCircularSegments(threadRadius). | ||
circularSegments = -1 | ||
# Number of segments along the length of the knot. Default makes roughly | ||
# square facets. | ||
linearSegments = -1 | ||
|
||
# These default values recreate Matlab Knot by Emmett Lalish: | ||
# https://www.thingiverse.com/thing:7080 | ||
|
||
kLoops = np.gcd(p, q) | ||
pk = p / kLoops | ||
qk = q / kLoops | ||
n = ( | ||
circularSegments | ||
if circularSegments > 2 | ||
else get_circular_segments(threadRadius) | ||
) | ||
m = linearSegments if linearSegments > 2 else n * qk * majorRadius / threadRadius | ||
|
||
offset = 2 | ||
circle = CrossSection.circle(1, n).translate([offset, 0]) | ||
|
||
def ax_rotate(x, theta): | ||
a, b = (x + 1) % 3, (x + 2) % 3 | ||
s, c = np.sin(theta), np.cos(theta) | ||
m = np.zeros((len(theta), 4, 4), dtype=np.float32) | ||
m[:, a, a], m[:, a, b] = c, s | ||
m[:, b, a], m[:, b, b] = -s, c | ||
m[:, x, x], m[:, 3, 3] = 1, 1 | ||
return m | ||
|
||
def func(pts): | ||
npts = pts.shape[0] | ||
x, y, z = pts[:, 0], pts[:, 1], pts[:, 2] | ||
psi = qk * np.arctan2(x, y) | ||
theta = psi * pk / qk | ||
x1 = np.sqrt(x * x + y * y) | ||
phi = np.arctan2(x1 - offset, z) | ||
|
||
v = np.zeros((npts, 4), dtype=np.float32) | ||
v[:, 0] = threadRadius * np.cos(phi) | ||
v[:, 2] = threadRadius * np.sin(phi) | ||
v[:, 3] = 1 | ||
r = majorRadius + minorRadius * np.cos(theta) | ||
|
||
m1 = ax_rotate(0, -np.arctan2(pk * minorRadius, qk * r)) | ||
m1[:, 3, 0] = minorRadius | ||
m2 = ax_rotate(1, theta) | ||
m2[:, 3, 0] = majorRadius | ||
m3 = ax_rotate(2, psi) | ||
|
||
v = v[:, None, :] @ (m1 @ m2 @ m3) | ||
return v[:, 0, :3] | ||
|
||
return circle.revolve(int(m)).warp_batch(func) | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters