Example #1
0
def test_rectangleMesh():
    plane = pgf.plane(pgf.var_vec3((0., 0., 0.)), pgf.var_vec3((1., 1., 0.)))
    box = pgf.box2(pgf.var_vec2((0., 0.)), pgf.var_vec2((15., 12.)))
    edgeLn = pgf.var_float(1.)

    rect = pgf.rectangleMesh(plane, box, edgeLn)
    area = pgf.area(rect)
    nfaces = pgf.numFaces(rect)
    nverts = pgf.numVertices(rect)

    assert 360 == pgf.read(nfaces)
    assert 208 == pgf.read(nverts)
    assert tu.equalf(180., pgf.read(area))
Example #2
0
def test_distance3():
    p1 = pgf.var_vec3()
    p2 = pgf.var_vec3()
    dist = pgf.distance(p1, p2)
    for _ in range(20):
        val1 = (random.uniform(1.2, 12.5), random.uniform(
            2.5, 15.6), random.uniform(22.3, 55.6))
        val2 = (random.uniform(1.26, 22.5), random.uniform(
            1.5, 13.9), random.uniform(23.5, 63.7))
        dval = math.sqrt(math.pow(val1[0] - val2[0], 2.) + math.pow(
            val1[1] - val2[1], 2.) + math.pow(val1[2] - val2[2], 2.))
        pgf.assign(p1, val1)
        pgf.assign(p2, val2)

        assert tu.equalf(pgf.read(dist), dval)
Example #3
0
def test_closestPointsOnMesh():
    mesh = pgf.scale(loadSmallBunny(), pgf.var_float(10.))

    inpts = pgf.var_vec3([
        (0.359824538230896, -0.012389957904815674, 0.3581507205963135),
        (-0.3318827152252197, 0.1699751615524292, 0.7063822150230408),
        (0.27124643325805664, -0.14796850085258484, 0.5440048575401306),
        (0.2950490713119507, 0.0309564471244812, 1.5690069198608398),
        (0.470700740814209, 0.559279203414917, 0.5738930106163025),
        (-0.6372849941253662, 0.5158957242965698, 0.9492948055267334),
        (-0.42367517948150635, 0.17821109294891357, 0.5325688719749451),
        (0.24817490577697754, 0.27643465995788574, 0.5003229975700378),
        (-0.5128110647201538, -0.4166657030582428, 1.868307113647461),
        (-0.08426868915557861, 0.14360648393630981, 0.6685295104980469)
    ])

    outpts = pgf.closestPoints(mesh, inpts)

    expected = [
        (0.35241958498954773, -0.022721359506249428, 0.3823484480381012),
        (-0.3473210334777832, 0.18098655343055725, 0.6997533440589905),
        (0.22252899408340454, -0.13979701697826385, 0.36583301424980164),
        (0.1671879142522812, -0.029879290610551834, 1.274683952331543),
        (0.22475071251392365, 0.2590671181678772, 0.5857457518577576),
        (-0.5479510426521301, 0.21973726153373718, 0.9220386743545532),
        (-0.423895001411438, 0.11360426992177963, 0.5336558818817139),
        (0.21963083744049072, 0.23689928650856018, 0.5136839151382446),
        (-0.6122115254402161, -0.3117043375968933, 1.5369797945022583),
        (-0.03959565982222557, 0.34772586822509766, 0.666935384273529)
    ]

    assert tu.equalf(expected, pgf.read(outpts))
Example #4
0
def test_cachedOffsetDataRegression():
    # This tests for a regression (lack of) happened while working on PR # 53.
    pt = pgf.var_vec3((0., 0., 0.))
    norm = pgf.var_vec3((0., 0., 1.))
    plane = pgf.plane(pt, norm)
    minpt = pgf.var_vec3((-.5, -.5, 0.))
    maxpt = pgf.var_vec3((.5, .5, 0.))
    box2 = pgf.box2(pgf.var_vec2((-.5, -.5)), pgf.var_vec2((.5, .5)))
    box3 = pgf.box3(minpt, maxpt)
    npts = pgf.var_int(4)
    cloud = pgf.randomPointsInBox(box3, npts)
    edgeLen = pgf.var_float(1)
    rect = pgf.rectangleMesh(plane, box2, edgeLen)
    distances = pgf.distance(pgf.graft(pgf.vertices(rect)), cloud)
    pdists = pgf.read(pgf.flatten(distances))
    assert len(pdists) == 16
Example #5
0
import pygalfunc as pgf
import pygalview as pgv

minpt = pgf.var_vec3((-1., -1., -1.))
maxpt = pgf.var_vec3((1., 1., 1.))
box = pgf.box3(minpt, maxpt)
npts = pgv.slideri32("Point count", 10, 1000, 100)

cloud = pgf.randomPointsInBox(box, npts)
hull = pgf.convexHullFromPoints(cloud)

pgv.show("Convex Hull", hull)
pgv.show("Points", cloud)
Example #6
0
import pygalfunc as pgf
import pygalview as pgv


pt = pgf.var_vec3((0., 0., 0.))
norm = pgf.var_vec3((0., 0., 1.))
plane = pgf.plane(pt, norm)
minpt = pgf.var_vec3((-.5, -.5, 0.))
maxpt = pgf.var_vec3((.5, .5, 0.))
box2 = pgf.box2(pgf.var_vec2((-.5, -.5)), pgf.var_vec2((.5, .5)))
box3 = pgf.box3(minpt, maxpt)
npts = pgv.slideri32("Point count", 5, 50, 25)
cloud = pgf.randomPointsInBox(box3, npts)

edgeLen = pgf.var_float(.01)
rect = pgf.rectangleMesh(plane, box2, edgeLen)

distances = pgf.distance(pgf.graft(pgf.vertices(rect)), cloud)
sortedDists = pgf.sort(distances, distances)
maxDist = pgf.listItem(sortedDists, pgf.sub(pgf.listLength(sortedDists), pgf.var_int(1)))

scheme = pgf.var_vec3([
    (0., 0., 1.),
    (0., 1., 0.),
    (1., 1., 0.),
    (1., 0., 0.)
])
colors = pgf.mapValueToColor(maxDist, pgf.var_vec2((.5, 1.2)), scheme)
colored = pgf.meshWithVertexColors(rect, colors)

circ, *_ = pgf.boundingCircle(cloud)
Example #7
0
import pygalfunc as pgf
import pygalview as pgv

POINTS = [
    (0, 0, 0),
    (1, 0, 0),
    (1, 1, 0),
    (-.3, 1, 0),
    (0, -1, 0),
]

pts = pgf.var_vec3(POINTS)
nums = pgf.toString(pgf.series(pgf.var_int(0), pgf.var_int(1), pgf.listLength(pts)))
idxPt = pgf.listItem(pts, pgv.slideri32("Index", 0, len(POINTS) - 1, 0))
circ, *_ = pgf.boundingCircle(pts)

pgv.show("indices", pgv.tags(nums, pts))
pgv.show("circle", circ)
pgv.show("points", pts)
pgv.print("Point at index", idxPt)