Ejemplo n.º 1
0
def _pointsOnEllipse(c, smaa, smia, ang, n):
    """Generates points lying on the ellipse with center c,
    semi-major/semi-minor axis lengths smaa/smia, and major axis
    angle (E of N) ang.
    """
    points = []
    c = g.cartesianUnitVector(c)
    north, east = g.northEast(c)
    sa = math.sin(math.radians(ang))
    ca = math.cos(math.radians(ang))
    smaa = math.radians(smaa * g.DEG_PER_ARCSEC)
    smia = math.radians(smia * g.DEG_PER_ARCSEC)
    aoff = random.uniform(0.0, 2.0 * math.pi)
    for i in xrange(n):
        a = aoff + 2.0 * i * math.pi / n
        x = smaa * math.cos(a)
        y = smia * math.sin(a)
        # rotate x, y by a
        nc = ca * x - sa * y
        ec = sa * x + ca * y
        cc = math.sqrt(abs(1.0 - nc * nc - ec * ec))
        points.append(g.normalize((cc * c[0] + nc * north[0] + ec * east[0],
                                   cc * c[1] + nc * north[1] + ec * east[1],
                                   cc * c[2] + nc * north[2] + ec * east[2])))
    return points
Ejemplo n.º 2
0
def _pointsOnEllipse(c, smaa, smia, ang, n):
    """Generates points lying on the ellipse with center c,
    semi-major/semi-minor axis lengths smaa/smia, and major axis
    angle (E of N) ang.
    """
    points = []
    c = g.cartesianUnitVector(c)
    north, east = g.northEast(c)
    sa = math.sin(math.radians(ang))
    ca = math.cos(math.radians(ang))
    smaa = math.radians(smaa * g.DEG_PER_ARCSEC)
    smia = math.radians(smia * g.DEG_PER_ARCSEC)
    aoff = random.uniform(0.0, 2.0 * math.pi)
    for i in xrange(n):
        a = aoff + 2.0 * i * math.pi / n
        x = smaa * math.cos(a)
        y = smia * math.sin(a)
        # rotate x, y by a
        nc = ca * x - sa * y
        ec = sa * x + ca * y
        cc = math.sqrt(abs(1.0 - nc * nc - ec * ec))
        points.append(
            g.normalize((cc * c[0] + nc * north[0] + ec * east[0],
                         cc * c[1] + nc * north[1] + ec * east[1],
                         cc * c[2] + nc * north[2] + ec * east[2])))
    return points
Ejemplo n.º 3
0
def _hemPoints(v, n):
    """Randomly generates a list of n points in the hemisphere
    given by the plane with normal v.
    """
    v = g.normalize(v)
    north, east = g.northEast(v)
    points = []
    for i in xrange(n):
        z = -1.0
        while z < 0.0:
            x = random.uniform(-1.0 + 1.0e-7, 1.0 - 1.0e-7)
            y = random.uniform(-1.0 + 1.0e-7, 1.0 - 1.0e-7)
            z = 1.0 - x * x - y * y
        z = math.sqrt(z)
        p = (z * v[0] + x * north[0] + y * east[0],
             z * v[1] + x * north[1] + y * east[1],
             z * v[2] + x * north[2] + y * east[2])
        points.append(g.normalize(p))
    return points
Ejemplo n.º 4
0
def _hemPoints(v, n):
    """Randomly generates a list of n points in the hemisphere
    given by the plane with normal v.
    """
    v = g.normalize(v)
    north, east = g.northEast(v)
    points = []
    for i in xrange(n):
        z = -1.0
        while z < 0.0:
            x = random.uniform(-1.0 + 1.0e-7, 1.0 - 1.0e-7)
            y = random.uniform(-1.0 + 1.0e-7, 1.0 - 1.0e-7)
            z = 1.0 - x * x - y * y
        z = math.sqrt(z)
        p = (z * v[0] + x * north[0] + y * east[0],
             z * v[1] + x * north[1] + y * east[1],
             z * v[2] + x * north[2] + y * east[2])
        points.append(g.normalize(p))
    return points
Ejemplo n.º 5
0
def _pointsOnCircle(c, r, n, clockwise=False):
    """Generates an n-gon lying on the circle with center c and
    radius r. Vertices are equi-spaced.
    """
    c = g.cartesianUnitVector(c)
    north, east = g.northEast(c)
    points = []
    sr = math.sin(math.radians(r))
    cr = math.cos(math.radians(r))
    aoff = random.uniform(0.0, 2.0 * math.pi)
    for i in xrange(n):
        a = 2.0 * i * math.pi / n
        if not clockwise:
            a = -a
        sa = math.sin(a + aoff)
        ca = math.cos(a + aoff)
        p = (ca * north[0] + sa * east[0], ca * north[1] + sa * east[1],
             ca * north[2] + sa * east[2])
        points.append(
            g.normalize((cr * c[0] + sr * p[0], cr * c[1] + sr * p[1],
                         cr * c[2] + sr * p[2])))
    return points
Ejemplo n.º 6
0
def _pointsOnPeriodicHypotrochoid(c, R, r, d, n):
    assert isinstance(r, int) and isinstance(R, int)
    assert R > r
    assert (2 * r) % (R - r) == 0
    points = []
    c = g.cartesianUnitVector(c)
    north, east = g.northEast(c)
    scale = 1.0 / (R - r + d + 1)
    period = (2 * r) / (R - r)
    if period % 2 != 0:
        period *= 2
    for i in xrange(n):
        theta = i * period * math.pi / n
        x = (R - r) * math.cos(theta) + d * math.cos((R - r) * theta / r)
        y = (R - r) * math.sin(theta) - d * math.sin((R - r) * theta / r)
        x *= scale
        y *= scale
        z = math.sqrt(1.0 - x * x - y * y)
        points.append(g.normalize((z * c[0] + x * north[0] + y * east[0],
                                   z * c[1] + x * north[1] + y * east[1],
                                   z * c[2] + x * north[2] + y * east[2])))
    return points
Ejemplo n.º 7
0
def _pointsOnPeriodicHypotrochoid(c, R, r, d, n):
    assert isinstance(r, int) and isinstance(R, int)
    assert R > r
    assert (2 * r) % (R - r) == 0
    points = []
    c = geom.cartesianUnitVector(c)
    north, east = geom.northEast(c)
    scale = 1.0 / (R - r + d + 1)
    period = (2 * r) / (R - r)
    if period % 2 != 0:
        period *= 2
    for i in range(n):
        theta = i * period * math.pi / n
        x = (R - r) * math.cos(theta) + d * math.cos((R - r) * theta / r)
        y = (R - r) * math.sin(theta) - d * math.sin((R - r) * theta / r)
        x *= scale
        y *= scale
        z = math.sqrt(1.0 - x * x - y * y)
        points.append(geom.normalize((z * c[0] + x * north[0] + y * east[0],
                                   z * c[1] + x * north[1] + y * east[1],
                                   z * c[2] + x * north[2] + y * east[2])))
    return points
Ejemplo n.º 8
0
def _pointsOnCircle(c, r, n, clockwise=False):
    """Generates an n-gon lying on the circle with center c and
    radius r. Vertices are equi-spaced.
    """
    c = g.cartesianUnitVector(c)
    north, east = g.northEast(c)
    points = []
    sr = math.sin(math.radians(r))
    cr = math.cos(math.radians(r))
    aoff = random.uniform(0.0, 2.0 * math.pi)
    for i in xrange(n):
        a = 2.0 * i * math.pi / n
        if not clockwise:
            a = -a
        sa = math.sin(a + aoff)
        ca = math.cos(a + aoff)
        p = (ca * north[0] + sa * east[0],
             ca * north[1] + sa * east[1],
             ca * north[2] + sa * east[2])
        points.append(g.normalize((cr * c[0] + sr * p[0],
                                   cr * c[1] + sr * p[1],
                                   cr * c[2] + sr * p[2])))
    return points