Exemplo n.º 1
0
    def position(self, t=None):
        """
        Args:
            t (float, optional):
                time [s]

        Returns:
            Value of self._position if t is None and if self._position is not
            None. Otherwise the actual position is calculated as function of
            time [m, m, m]

        Note:
            The calculated position is NOT stored as 'self._position'
        """
        if t is None and self._position is not None:
            return self._position
        if self._wayPoints is None:
            return self._position

        if t is None or t < 0.:
            t = 0.
        if t >= self._wayPoints[-1].t:
            P = self._wayPoints[-1]
            return xyz(P.x, P.y, P.z)

        # P = P' + (P"-P') * (t-t') / (t"-t')
        iAhead = self.iWayPointAhead(t)
        DP = self._wayPoints[iAhead] - self._wayPoints[iAhead - 1]
        dt = t - self._wayPoints[iAhead - 1].t
        Dt = self._wayPoints[iAhead].t - self._wayPoints[iAhead - 1].t
        P = self._wayPoints[iAhead - 1] + DP * (dt / Dt)
        return xyz(P.x, P.y, P.z)
Exemplo n.º 2
0
def getSphereCoord(x, y):
    global width
    global height
    global r
    coordx = x - width/2
    coordy = height/2 - y

    if coordx * coordx + coordy * coordy <= r * r:
        result = xyz(coordx, coordy, math.sqrt(r * r - coordx * coordx - coordy * coordy))
        return result
    else:
        try:
            tempx = math.sqrt((r * r) / (1 + (coordy * coordy) / (coordx * coordx)))
        except:
            tempx = 0
        try:
            tempy = math.sqrt((r * r) / (1 + (coordx * coordx) / (coordy * coordy)))
        except:
            tempy = 0
        if coordx >= 0 and coordy >= 0:
            return xyz(tempx, tempy, 0.0)
        elif coordx >= 0 and coordy < 0:
            return xyz(tempx, (-1)*tempy, 0.0)
        elif coordx < 0 and coordy >= 0:
            return xyz((-1) * tempx, tempy, 0.0)
        elif coordx < 0 and coordy < 0:
            return xyz((-1) * tempx, (-1) * tempy, 0.0)
Exemplo n.º 3
0
def rdata(l, Al):
    x = xyz(l, Al)[0]
    y = xyz(l, Al)[1]
    t = tem(x, y)
    if t <= 5000:
        a, b, c = np.loadtxt("fm.csv",
                             delimiter=",",
                             usecols=(0, 1, 2),
                             unpack=True,
                             skiprows=1)
    elif t <= 10000:
        a, b, c = np.loadtxt("fm.csv",
                             delimiter=",",
                             usecols=(3, 4, 5),
                             unpack=True,
                             skiprows=1)
    else:
        a, b, c = np.loadtxt("fm.csv",
                             delimiter=",",
                             usecols=(6, 7, 8),
                             unpack=True,
                             skiprows=1)
    ur = fm(a[0], b[0], c[0], t)
    vr = fm(a[1], b[1], c[1], t)
    Uri = []
    Vri = []
    Wri = []
    for ui in range(2, 10):
        Uri.append(fm(a[ui], b[ui], c[ui], t))
    for vi in range(16, 24):
        Vri.append(fm(a[vi], b[vi], c[vi], t))
    for wi in range(30, 38):
        Wri.append(fm(a[wi], b[wi], c[wi], t))

    return [ur, vr, Uri, Vri, Wri]
Exemplo n.º 4
0
def uvkt(l, Al):
    x = xyz(l, Al)[0]
    y = xyz(l, Al)[1]
    uk = 4 * x / (-2 * x + 12 * y + 3)
    vk = 6 * y / (-2 * x + 12 * y + 3)
    t = tem(x, y)
    return [uk, vk, t]
Exemplo n.º 5
0
def ki(l, Al):
    a1, a2, a3, a4, a5, a6, a7, a8 = np.loadtxt("β.csv",
                                                delimiter=",",
                                                usecols=(1, 2, 3, 4, 5, 6, 7,
                                                         8),
                                                unpack=True)
    xd, yd, zd = np.loadtxt("xyz.csv",
                            delimiter=",",
                            usecols=(1, 2, 3),
                            unpack=True)
    aall = [a1, a2, a3, a4, a5, a6, a7, a8]
    p = xyz(l, Al)[-1]
    k = xyz(l, Al)[-2]
    uki = []
    vki = []
    Yki = []
    for i in range(8):
        g = aall[i]
        Xk = 0
        Yk = 0
        Zk = 0
        for t in range(len(p)):
            d = k * g[t] * p[t] * xd[t] * 5
            e = k * g[t] * p[t] * yd[t] * 5
            f = k * g[t] * p[t] * zd[t] * 5
            Xk = Xk + d
            Yk = Yk + e
            Zk = Zk + f
        uk = 4 * Xk / (Xk + 15 * Yk + 3 * Zk)
        vk = 6 * Yk / (Xk + 15 * Yk + 3 * Zk)
        uki.append(uk)
        vki.append(vk)
        Yki.append(Yk)
    return [uki, vki, Yki]
Exemplo n.º 6
0
    def setTrajectory(self, way, rot=None, speed=None, tBegin=0, tEnd=None):
        """
        Defines list of waypoints

        Args:
            way (array_like of xyz or xyzt):
                way points in 3D space [m, m, m] or [m, m, m, s]

            rot (array_like of xyz):
                rotation of waypoints in 3D space [rad], size can be 0, 1, or
                length of wayPoints

            speed (float, optional):
                constant magnitude of object velocity [m/s]

            tBegin (float, optional):
                start time [s]

            tEnd (float, optional):
                end time [s]
        """
        self._wayPoints = list(way)
        if len(self._wayPoints) <= 1:
            return
        self._wayPoints = [xyzt(point=P) for P in self._wayPoints]

        way = [0.]
        for i in range(1, len(self._wayPoints)):
            Dl = (self._wayPoints[i] - self._wayPoints[i - 1]).magnitude()
            way.append(way[i - 1] + Dl)

        if rot is None or len(rot) == 0:
            rot = [xyz()]
        assert len(rot) == 1 or len(rot) == len(self._wayPoints)
        if len(rot) == 1:
            self._rotations = rot * len(self._wayPoints)
        else:
            self._rotations = [xyz(point=r) for r in rot]

        if speed is None:
            if tEnd is None or isclose(tEnd, 0.):
                for P in self._wayPoints:
                    P.t = 0.
                return
            speed = way[-1] / tEnd

        self._wayPoints[0].t = tBegin
        for i in range(1, len(self._wayPoints)):
            dt = (way[i] - way[i - 1]) / speed
            self._wayPoints[i].t = self._wayPoints[i - 1].t + dt

        self._position = self._wayPoints[0]
        self._velocity = self.velocity(0)
        self._rotation = self.rotation(0)

        del way
Exemplo n.º 7
0
    def __init__(self, identifier='Move'):
        super().__init__(identifier=identifier)

        self._wayPoints = None  # array of wayPoints [m, m, m, s]
        self._rotations = None  # rotations in 3D space [rad]
        self._position = xyz()  # object position in 3D space [m]
        self._velocity = xyz()  # velocity in 3D space [m/s]
        self._rotation = xyz()  # rotation in 3D space [rad]
        self._iLastWayPoint = 0  # index of last passed way point
        self._trajectoryHistory = None  # plot data
Exemplo n.º 8
0
def display():
    global globalTranslate
    global splinePoints1
    global splinePoints2
    global eye

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    loadGlobalCoord()

    glPushMatrix()
    
    glTranslatef(globalTranslate.x, globalTranslate.y, globalTranslate.z)

    drawCrossSections(splinePoints1)
    drawCatmullRomSections(splinePoints2)

    c1 = cube(xyz(-25, 10, 10), xyz(-25, 10, -10), xyz(-5, 10, -10), xyz(-5, 10, 10), xyz(-25, -10, 10), xyz(-25, -10, -10), xyz(-5, -10, -10), xyz(-5, -10, 10))
    s1 = c1.getSortedSurfaces(eye)
    drawMaterialSurfaces(s1)

    c2 = cube(xyz(5, 10, 10), xyz(5, 10, -10), xyz(25, 10, -10), xyz(25, 10, 10), xyz(5, -10, 10), xyz(5, -10, -10), xyz(25, -10, -10), xyz(25, -10, 10))
    s2 = c2.getSortedSurfaces(eye)
    drawTranslucentSurfaces(s2)
    

    glPopMatrix()

    lightOff()
    lightOn()

    glutSwapBuffers()
Exemplo n.º 9
0
def translate(x1, y1, x2, y2):
    global globalTranslate
    xyz1 = 	xyz(x1 - width/2, height/2 - y1, 0)
    xyz2 = 	xyz(x2 - width/2, height/2 - y2, 0)
    xyz1 = getRealCoord(xyz1)
    xyz2 = getRealCoord(xyz2)

    globalTranslate.x += 0.1 * (xyz2.x - xyz1.x)
    globalTranslate.y += 0.1 * (xyz2.y - xyz1.y)
    globalTranslate.z += 0.1 * (xyz2.z - xyz1.z)

    glutPostRedisplay()
Exemplo n.º 10
0
def scaleRotatePosition(crossSections):
    result = []
    for crossSection in crossSections:
        controllPoints = crossSection['controllPoints']
        scale = crossSection['scale']
        rotate = crossSection['rotation']
        position = crossSection['position']
        tempResult = []
        for controllPoint in controllPoints:
            realControllPoint = xyz(controllPoint.x * scale, controllPoint.y * scale, controllPoint.z * scale)
            realControllPoint = quaternion.rotate(rotate, realControllPoint)
            realControllPoint = xyz(realControllPoint.x + position.x, realControllPoint.y + position.y, realControllPoint.z + position.z)
            tempResult.append(realControllPoint)
        result.append(tempResult)
    return result
Exemplo n.º 11
0
def toBsplinePoints(realControllPoint):
    i = 0
    result = []
    p = copy.deepcopy(realControllPoint)
    p.append(p[0])
    p.append(p[1])
    p.append(p[2])
    while i + 4 <= len(p):
        t = 0
        while t <= 1.0:
            it = 1.0 - t
            b0 = it * it * it / 6
            b1 = (3 * t * t * t - 6 * t * t + 4) / 6
            b2 = (-3 * t * t * t + 3 * t * t + 3 * t + 1) / 6
            b3 = t * t * t / 6
            x = b0 * p[i].x + b1 * p[i + 1].x + b2 * p[i + 2].x + b3 * p[i +
                                                                         3].x
            y = b0 * p[i].y + b1 * p[i + 1].y + b2 * p[i + 2].y + b3 * p[i +
                                                                         3].y
            z = b0 * p[i].z + b1 * p[i + 1].z + b2 * p[i + 2].z + b3 * p[i +
                                                                         3].z
            result.append(xyz(x, y, z))
            t += 0.3333
        i += 1
    return result
Exemplo n.º 12
0
def toCatmullRomPoints(realControllPoint):
    i = 0
    result = []
    p = copy.deepcopy(realControllPoint)
    p.append(p[0])
    p.append(p[1])
    p.append(p[2])
    while i + 4 <= len(p):
        t = 0
        while t <= 1.0:
            t2 = t * t
            t3 = t2 * t
            x = ((2 * p[i + 1].x) + ((-p[i].x + p[i + 2].x) * t) +
                 ((2 * p[i].x - 5 * p[i + 1].x + 4 * p[i + 2].x - p[i + 3].x) *
                  t2) +
                 ((-p[i].x + 3 * p[i + 1].x - 3 * p[i + 2].x + p[i + 3].x) *
                  t3)) * 0.5
            y = ((2 * p[i + 1].y) + ((-p[i].y + p[i + 2].y) * t) +
                 ((2 * p[i].y - 5 * p[i + 1].y + 4 * p[i + 2].y - p[i + 3].y) *
                  t2) +
                 ((-p[i].y + 3 * p[i + 1].y - 3 * p[i + 2].y + p[i + 3].y) *
                  t3)) * 0.5
            z = ((2 * p[i + 1].z) + ((-p[i].z + p[i + 2].z) * t) +
                 ((2 * p[i].z - 5 * p[i + 1].z + 4 * p[i + 2].z - p[i + 3].z) *
                  t2) +
                 ((-p[i].z + 3 * p[i + 1].z - 3 * p[i + 2].z + p[i + 3].z) *
                  t3)) * 0.5
            result.append(xyz(x, y, z))
            t += 0.3333
        i += 1
    return result
Exemplo n.º 13
0
def toCatmullRomSurface(crossSections):
    result = []
    sections = copy.deepcopy(crossSections)
    i = 0
    while i + 4 <= len(sections):
        t = 0
        controllPoints = []
        scale = None
        rotation = None
        position = None
        while t <= 1.0:
            t2 = t * t
            t3 = t2 * t
            for p0, p1, p2, p3 in zip(sections[i]["controllPoints"], sections[i+1]["controllPoints"], sections[i+2]["controllPoints"], sections[i+3]["controllPoints"]):
                x = ((2 * p1.x) + ((-p0.x + p2.x) * t) + ((2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2) + ((-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t3)) * 0.5
                y = ((2 * p1.y) + ((-p0.y + p2.y) * t) + ((2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2) + ((-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t3)) * 0.5
                z = ((2 * p1.z) + ((-p0.z + p2.z) * t) + ((2 * p0.z - 5 * p1.z + 4 * p2.z - p3.z) * t2) + ((-p0.z + 3 * p1.z - 3 * p2.z + p3.z) * t3)) * 0.5
                controllPoints.append(xyz(x, y, z))
            scale = ((2 * sections[i+1]["scale"]) + ((-sections[i]["scale"] + sections[i+2]["scale"]) * t) + ((2 * sections[i]["scale"] - 5 * sections[i+1]["scale"] + 4 * sections[i+2]["scale"] - sections[i+3]["scale"]) * t2) + ((-sections[i]["scale"] + 3 * sections[i+1]["scale"] - 3 * sections[i+2]["scale"] + sections[i+3]["scale"]) * t3)) * 0.5
            position = ((sections[i+1]["position"]  * 2) + ((sections[i]["position"] * (-1) + sections[i+2]["position"]) * t) + ((sections[i]["position"] * 2 - sections[i+1]["position"] * 5 + sections[i+2]["position"] * 4 - sections[i+3]["position"]) * t2) + ((sections[i]["position"] * (-1) + sections[i+1]["position"] * 3 - sections[i+2]["position"] * 3 + sections[i+3]["position"]) * t3)) * 0.5
            rotation = ((sections[i+1]["rotation"]  * 2) + ((sections[i]["rotation"] * (-1) + sections[i+2]["rotation"]) * t) + ((sections[i]["rotation"] * 2 - sections[i+1]["rotation"] * 5 + sections[i+2]["rotation"] * 4 - sections[i+3]["rotation"]) * t2) + ((sections[i]["rotation"] * (-1) + sections[i+1]["rotation"] * 3 - sections[i+2]["rotation"] * 3 + sections[i+3]["rotation"]) * t3)) * 0.5
            result.append({
                "controllPoints": controllPoints,
                "scale": scale,
                "rotation": rotation,
                "position": position,
            })
            t += 0.33
        i += 1
    return result
Exemplo n.º 14
0
 def toAngleAxis(self):
     angle = 2 * math.acos(self.w)
     tempx = self.x / math.sqrt(1 - self.w * self.w)
     tempy = self.y / math.sqrt(1 - self.w * self.w)
     tempz = self.z / math.sqrt(1 - self.w * self.w)
     axis = xyz(tempx, tempy, tempz)
     return (angle, axis)
Exemplo n.º 15
0
    def velocity(self, t=None):
        """
        Args:
            t (float, optional):
                time [s]

        Returns:
            (xyz):
                Value of self._velocity if 't' is None and self._velocity is
                not None. Otherwise the actual velocity is calculated as
                function of time [m/s]

        Note:
            The calculated velocity is NOT stored as 'self._velocity'
        """
        if t is None:
            if self._velocity is not None:
                return self._velocity
            t = 0.
        if self._wayPoints is None:
            return xyz()
        iAhead = self.iWayPointAhead(t)
        DP = self._wayPoints[iAhead] - self._wayPoints[iAhead - 1]
        Dt = self._wayPoints[iAhead].t - self._wayPoints[iAhead - 1].t

        return DP * (1 / Dt)
Exemplo n.º 16
0
    def rotation(self, t=None):
        """
        Args:
            t (float, optional):
                time [s]

        Returns:
            Value of self._rotations if t is None and if self._rotations is not
            None. Otherwise the actual rotation is calculated as function of
            time [rad]

        Note:
            The calculated rotation is NOT stored as 'self._rotation'
        """
        if t is None and self._rotations is not None:
            return self._rotations
        if self._wayPoints is None:
            return xyz()

        if t is None or t < 0.:
            t = 0.
        if t >= self._wayPoints[-1].t:
            return self._rotations[-1]

        # R = R' + (R"-R') * (t-t') / (t"-t')
        iAhead = self.iWayPointAhead(t)
        DR = self._rotations[iAhead] - self._rotations[iAhead - 1]
        dt = t - self._wayPoints[iAhead - 1].t
        Dt = self._wayPoints[iAhead].t - self._wayPoints[iAhead - 1].t
        return self._rotations[iAhead - 1] + DR * (dt / Dt)
Exemplo n.º 17
0
    def initialCondition(self):
        """
        Initializes object positionm velocity and rotation
        """
        super().initialCondition()

        if self._wayPoints is not None:
            self._position = self._wayPoints[0]
            self._velocity = self.velocity(0)
            self._rotation = self.rotation(0)
        else:
            self._position = xyz()
            self._velocity = xyz()
            self._rotation = xyz()

        if self.silent:
            self._trajectoryHistory = None
        else:
            self._trajectoryHistory = \
                [[self._position.x], [self._position.y], [self._position.z],
                 [self._velocity.x], [self._velocity.y], [self._velocity.z],
                 [self._rotation.x], [self._rotation.y], [self._rotation.z]]
Exemplo n.º 18
0
def ra(l, Al):
    rd = rdata(l, Al)
    kd = WUV(l, Al)
    Uri = rd[2]
    Vri = rd[3]
    Wri = rd[4]
    Uki = kd[0]
    Vki = kd[1]
    Wki = kd[2]
    ris = []
    for i in range(len(Uri)):
        u = (Uri[i] - Uki[i])**2
        v = (Vri[i] - Vki[i])**2
        w = (Wri[i] - Wki[i])**2
        e = math.sqrt(u + v + w)
        ri = 100 - 4.6 * e
        ris.append(ri)
    Ra = sum(ris) / 8
    x = xyz(l, Al)[0]
    y = xyz(l, Al)[1]
    t = tem(x, y)
    return Ra, t, x, y
Exemplo n.º 19
0
async def on_message(message):
    if message.author.id == 365975655608745985:
        with open('settings.json') as s:
            settings = json.load(s)

        if message.channel.id in settings['allowed_channels_ids']:
            if message.embeds:
                if 'Guess' in message.embeds[0].description:
                    url = message.embeds[0].image.url
                    name = xyz(url).start()
                    timer = settings['timer']

                    await asyncio.sleep(timer)

                    await message.channel.send(f'p!catch {name}')

    await client.process_commands(message)
Exemplo n.º 20
0
                       angles='xy',
                       scale_units='xy')
            plt.xlim(0, )
            plt.xlabel('y')
            plt.ylabel('z')
            plt.grid()
            plt.show()


# Examples ####################################################################

if __name__ == '__main__':
    ALL = 1
    #   y
    way = [
        xyz(.0, .0, .0),  #   ^
        xyz(.1, .1, .0),  # +1|      /\
        xyz(.2, .2, .0),  #   |    /    \
        xyz(.3, .1, .0),  #   |  /        \             0.8
        xyz(.4, .0, .0),  # 0 |/----0.2-----\----0.6-----/-->
        xyz(.5, -.1, .0),  #   |            0.4\        /    x
        xyz(.6, -.2, .0),  #   |                 \    /
        xyz(.7, -.1, .0),  # -1|                   \/
        xyz(.8, .0, .0)
    ]  #   | trajectory W=W(t)

    rot = [
        xyz(20 * np.sin(i * 3), 4 * i - 20, i * i - 30)
        for i in range(len(way))
    ]
    print(len(rot), [str(rot[i]) for i in range(9)])
Exemplo n.º 21
0
def getRealCoord(coord):
    global rq
    global rq_
    p = quaternion(0, coord.x, coord.y, coord.z)
    p = rq * p * rq_
    return xyz(p.x, p.y, p.z)
Exemplo n.º 22
0
            if x5 > xbs:
                l4s.append(0.1 * 2**i)
    if ok2 == 0:
        l4 = l4s[0]
        while True:
            j = (l3 + l4) / 2
            x5 = twomix(p1, p2, j)[0]
            if xbr < x5 < xbs:
                ok2 = j
                break
            else:
                if x5 < xbr:
                    l3 = j
                if x5 > xbs:
                    l4 = j
    # 以上求出b的比例参数
    return [ok2, 1, ok1]


if __name__ == '__main__':
    start = time.clock()
    al = twoopt([460, 25, 540, 36, 615, 13], [0.28, 0.35], 0.00001)
    end = time.clock()
    r = ra([460, 25, 540, 36, 615, 13], al)
    p = xyz([460, 25, 540, 36, 615, 13], al)[-1]
    kl = ler(p)
    print(r)
    print(al)
    print(kl)
    print(end - start)
Exemplo n.º 23
0
def twoopt(l, g, r):
    xb = xyz(l[0:2], [1])[0]
    yb = xyz(l[0:2], [1])[1]
    xg = xyz(l[2:4], [1])[0]
    yg = xyz(l[2:4], [1])[1]
    xr = xyz(l[4:6], [1])[0]
    yr = xyz(l[4:6], [1])[1]
    c1 = g[0]
    c2 = g[1]
    a = (c1 - xb)**2 - r**2
    b = 2 * (yb - c2) * (c1 - xb)
    c = (yb - c2)**2 - r**2
    if xs(a, b, c):
        k1, k2 = xs(a, b, c)
    else:
        return None
    k3 = (yg - yr) / (xg - xr)
    x1 = (yr - yb + k1 * xb - k3 * xr) / (k1 - k3)
    x2 = (yr - yb + k2 * xb - k3 * xr) / (k2 - k3)
    if x1 < x2:
        xp = x1
        xq = x2
    else:
        xp = x2
        xq = x1
    # 以上,求出xp,xq,下面求ok1即r的比例参数
    l2s = []
    l1 = 0
    ok1 = 0
    for i in range(10):
        x0 = xyz(l[2:6], [1, 0.1 * 2**i])[0]
        if xp < x0 < xq:
            ok1 = 0.1 * 2**i
        else:
            if x0 < xp:
                l1 = 0.1 * 2**i
            if x0 > xq:
                l2s.append(0.1 * 2**i)
    if ok1 == 0:
        l2 = l2s[0]
        while True:
            j = (l1 + l2) / 2
            x0 = xyz(l[2:6], [1, j])[0]
            if xp < x0 < xq:
                ok1 = j
                break
            else:
                if x0 < xp:
                    l1 = j
                if x0 > xq:
                    l2 = j
    # 以上,求出g,r的比例参数,下面求b的比例参数
    xp0 = xyz(l[2:6], [1, ok1])[0]
    yp0 = xyz(l[2:6], [1, ok1])[1]
    p1 = xyz(l[2:6], [1, ok1])[-1]
    p2 = xyz(l[0:2], [1])[-1]
    kb = (yb - yp0) / (xb - xp0)
    a1 = 1 + kb**2
    b1 = 2 * kb * (yb - c2 - kb * xb) - 2 * c1
    d1 = (yb - c2 - kb * xb)**2 - r**2 + c1**2
    if xs(a1, b1, d1):
        x3, x4 = xs(a1, b1, d1)
    else:
        return None
    if x3 > x4:
        xbr = x4
        xbs = x3
    else:
        xbr = x3
        xbs = x4
    # 以上求出xbr和xbs,下面求b的比例参数
    l4s = []
    l3 = 0
    ok2 = 0
    for i in range(10):
        x5 = twomix(p1, p2, 0.1 * 2**i)[0]
        if xbr < x5 < xbs:
            ok2 = 0.1 * 2**i
        else:
            if x5 < xbr:
                l3 = 0.1 * 2**i
            if x5 > xbs:
                l4s.append(0.1 * 2**i)
    if ok2 == 0:
        l4 = l4s[0]
        while True:
            j = (l3 + l4) / 2
            x5 = twomix(p1, p2, j)[0]
            if xbr < x5 < xbs:
                ok2 = j
                break
            else:
                if x5 < xbr:
                    l3 = j
                if x5 > xbs:
                    l4 = j
    # 以上求出b的比例参数
    return [ok2, 1, ok1]
Exemplo n.º 24
0
def helio_jd(date, ra, dec, b1950=False, time_diff=False):
   """
    NAME:
         HELIO_JD
    PURPOSE:
         Convert geocentric (reduced) Julian date to heliocentric Julian date
    EXPLANATION:
         This procedure correct for the extra light travel time between the Earth
         and the Sun.
   
          An online calculator for this quantity is available at
          http://www.physics.sfasu.edu/astro/javascript/hjd.html
    CALLING SEQUENCE:
          jdhelio = HELIO_JD( date, ra, dec, /B1950, /TIME_DIFF)
   
    INPUTS
          date - reduced Julian date (= JD - 2400000), scalar or vector, MUST
                  be double precision
          ra,dec - scalars giving right ascension and declination in DEGREES
                  Equinox is J2000 unless the /B1950 keyword is set
   
    OUTPUTS:
          jdhelio - heliocentric reduced Julian date.  If /TIME_DIFF is set, then
                    HELIO_JD() instead returns the time difference in seconds
                    between the geocentric and heliocentric Julian date.
   
    OPTIONAL INPUT KEYWORDS
          /B1950 - if set, then input coordinates are assumed to be in equinox
                   B1950 coordinates.
          /TIME_DIFF - if set, then HELIO_JD() returns the time difference
                   (heliocentric JD - geocentric JD ) in seconds
   
    EXAMPLE:
          What is the heliocentric Julian date of an observation of V402 Cygni
          (J2000: RA = 20 9 7.8, Dec = 37 09 07) taken June 15, 1973 at 11:40 UT?
   
          IDL> juldate, [1973,6,15,11,40], jd      ;Get geocentric Julian date
          IDL> hjd = helio_jd( jd, ten(20,9,7.8)*15., ten(37,9,7) )
   
          ==> hjd = 41848.9881
   
    Wayne Warren (Raytheon ITSS) has compared the results of HELIO_JD with the
    FORTRAN subroutines in the STARLINK SLALIB library (see
    http://star-www.rl.ac.uk/).
                                                     Time Diff (sec)
         Date               RA(2000)   Dec(2000)  STARLINK      IDL
   
    1999-10-29T00:00:00.0  21 08 25.  -67 22 00.  -59.0        -59.0
    1999-10-29T00:00:00.0  02 56 33.4 +00 26 55.  474.1        474.1
    1940-12-11T06:55:00.0  07 34 41.9 -00 30 42.  366.3        370.2
    1992-02-29T03:15:56.2  12 56 27.4 +42 10 17.  350.8        350.9
    2000-03-01T10:26:31.8  14 28 36.7 -20 42 11.  243.7        243.7
    2100-02-26T09:18:24.2  08 26 51.7 +85 47 28.  104.0        108.8
    PROCEDURES CALLED:
          bprecess, xyz
   
    REVISION HISTORY:
          Algorithm from the book Astronomical Photometry by Henden, p. 114
          Written,   W. Landsman       STX     June, 1989
          Make J2000 default equinox, add B1950, /TIME_DIFF keywords, compute
          variation of the obliquity      W. Landsman   November 1999
          Converted to python 	Sergey Koposov July 2010
   """
   
   #Because XYZ uses default B1950 coordinates, we'll convert everything to B1950
   
   if not b1950:
      ra1, dec1 = bprecess(ra, dec)
   else:   
      ra1 = ra
      dec1 = dec
   
   
   delta_t = (array(date).astype(float) - 33282.42345905e0) / 36525.0e0
   epsilon_sec = poly1d([44.836e0, -46.8495, -0.00429, 0.00181][::-1])(delta_t)
   epsilon = deg2rad(23.433333e0 + epsilon_sec / 3600.0e0)
   ra1 = deg2rad(ra1)
   dec1 = deg2rad(dec1)
   
   x, y, z, tmp, tmp, tmp = xyz(date)
   
   #Find extra distance light must travel in AU, multiply by 1.49598e13 cm/AU,
   #and divide by the speed of light, and multiply by 86400 second/year
   
   time = -499.00522e0 * (cos(dec1) * cos(ra1) * x + (tan(epsilon) * sin(dec1) + cos(dec1) * sin(ra1)) * y)
   if time_diff:   
      return time
   else:   
      return array(date).astype(float) + time / 86400.0e0
Exemplo n.º 25
0
def processInputFile():
    global splinePoints1
    global splinePoints2

    f = open('myinput.txt', 'r')
    lines = f.readlines()

    # parse
    for idx, line in enumerate(lines):
        lines[idx] = line.split('#')[0]
    
    i = 0
    while i < len(lines):
        if lines[i].isspace() or lines[i] == '':
            lines.remove(lines[i])
        else:
            i += 1

    for idx, line in enumerate(lines):
        if line.isspace() or line == '':
            lines.remove(line)
    
    curveType = lines[0].split()[0]
    crossSectionNum = int(lines[1].split()[0])
    controllPointNum = int(lines[2].split()[0])
    crossSections = []
    for i in range(0, crossSectionNum):
        controllPoints = []
        for j in range(0, controllPointNum):
            x = float(lines[3 + i * (controllPointNum + 3) + j].split()[0])
            z = float(lines[3 + i * (controllPointNum + 3) + j].split()[1])
            controllPoint = xyz(x, 0, z)
            controllPoints.append(controllPoint)
        scaleFactor = float(lines[3 + i * (controllPointNum + 3) + controllPointNum].split()[0])
        theta = float(lines[3 + i * (controllPointNum + 3) + controllPointNum + 1].split()[0])
        x = float(lines[3 + i * (controllPointNum + 3) + controllPointNum + 1].split()[1])
        y = float(lines[3 + i * (controllPointNum + 3) + controllPointNum + 1].split()[2])
        z = float(lines[3 + i * (controllPointNum + 3) + controllPointNum + 1].split()[3])
        rotation = quaternion(math.cos(0.5 * theta), x * math.sin(0.5 * theta), y * math.sin(0.5 * theta), z * math.sin(0.5 * theta))
        x = float(lines[3 + i * (controllPointNum + 3) + controllPointNum + 2].split()[0])
        y = float(lines[3 + i * (controllPointNum + 3) + controllPointNum + 2].split()[1])
        z = float(lines[3 + i * (controllPointNum + 3) + controllPointNum + 2].split()[2])
        position = xyz(x, y, z)
        crossSections.append({
            "controllPoints": controllPoints,
            "scale": scaleFactor,
            "rotation": rotation,
            "position": position,
        })

    crossSections.insert(0, crossSections[0])
    crossSections.append(crossSections[len(crossSections) - 1])

    realControllPoints = scaleRotatePosition(crossSections)
    if curveType == 'BSPLINE':
        for realControllPoint in realControllPoints:
            splinePoints1.append(toBsplinePoints(realControllPoint))
    elif curveType == 'CATMULL_ROM':
        for realControllPoint in realControllPoints:
            splinePoints1.append(toCatmullRomPoints(realControllPoint))    

    catmullRomCrossSections = toCatmullRomSurface(crossSections)
    realControllPoints = scaleRotatePosition(catmullRomCrossSections)
    if curveType == 'BSPLINE':
        for realControllPoint in realControllPoints:
            splinePoints2.append(toBsplinePoints(realControllPoint))
    elif curveType == 'CATMULL_ROM':
        for realControllPoint in realControllPoints:
            splinePoints2.append(toCatmullRomPoints(realControllPoint))
Exemplo n.º 26
0
 def rotate(rotateQuaternion, point):
     pointQuaternion = quaternion(0, point.x, point.y, point.z)
     rotateQuaternion_ = rotateQuaternion.conjugate()
     result = rotateQuaternion * pointQuaternion * rotateQuaternion_
     return xyz(result.x, result.y, result.z)
Exemplo n.º 27
0
import math
import json
import copy
import OpenGL
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from xyz import xyz
from quaternion import quaternion
from cube import cube

width = 1200
height = 800
r = 340
perspectiveAngle = 45.0
eye = xyz(0.0, 0.0, 100.0)
ori = xyz(0.0, 0.0, 0.0)
up = xyz(0.0, 1.0, 0.0)
rotMatrix = [
	1, 0, 0, 0,
	0, 1, 0, 0,
	0, 0, 1, 0,
	0, 0, 0, 1
]
mousePosX = -1
mousePosY = -1
leftButton = False
translating = False
dolly = False
zoom = False
Exemplo n.º 28
0
# Script:  dump2xyz.py
# Purpose: convert a LAMMPS dump file to XYZ format
# Syntax:  dump2xyz.py dumpfile Nid Ntype Nx Ny Nz xyzfile
#          dumpfile = LAMMPS dump file in native LAMMPS format
#          Nid,Ntype,Nx,Ny,Nz = columns #s for ID,type,x,y,z
#                               (usually 1,2,3,4,5)
#          xyzfile = new XYZ file
# Author:  Steve Plimpton (Sandia), sjplimp at sandia.gov

import sys,os
path = os.environ["LAMMPS_PYTHON_TOOLS"]
sys.path.append(path)
from dump import dump
from xyz import xyz

if len(sys.argv) != 8:
  raise StandardError, "Syntax: dump2xyz.py dumpfile Nid Ntype Nx Ny Nz xyzfile"

dumpfile = sys.argv[1]
nid = int(sys.argv[2])
ntype = int(sys.argv[3])
nx = int(sys.argv[4])
ny = int(sys.argv[5])
nz = int(sys.argv[6])
xyzfile = sys.argv[7]

d = dump(dumpfile)
d.map(nid,"id",ntype,"type",nx,"x",ny,"y",nz,"z")
x = xyz(d)
x.one(xyzfile)
Exemplo n.º 29
0
# Script:  dump2xyz.py
# Purpose: convert a LAMMPS dump file to XYZ format
# Syntax:  dump2xyz.py dumpfile Nid Ntype Nx Ny Nz xyzfile
#          dumpfile = LAMMPS dump file in native LAMMPS format
#          Nid,Ntype,Nx,Ny,Nz = columns #s for ID,type,x,y,z
#                               (usually 1,2,3,4,5)
#          xyzfile = new XYZ file
# Author:  Steve Plimpton (Sandia), sjplimp at sandia.gov

import sys,os
path = os.environ["LAMMPS_PYTHON_TOOLS"]
sys.path.append(path)
from dump import dump
from xyz import xyz

if len(sys.argv) != 8:
  raise StandardError, "Syntax: dump2xyz.py dumpfile Nid Ntype Nx Ny Nz xyzfile"

dumpfile = sys.argv[1]
nid = int(sys.argv[2])
ntype = int(sys.argv[3])
nx = int(sys.argv[4])
ny = int(sys.argv[5])
nz = int(sys.argv[6])
xyzfile = sys.argv[7]

d = dump(dumpfile)
d.map(nid,"id",ntype,"type",nx,"x",ny,"y",nz,"z")
x = xyz(d)
x.one(xyzfile)
Exemplo n.º 30
0
import sys
import math
import json
import copy
import OpenGL
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from xyz import xyz
from quaternion import quaternion

width = 1200
height = 800
r = 340
perspectiveAngle = 45.0
eye = xyz(0.0, 0.0, 100.0)
ori = xyz(0.0, 0.0, 0.0)
up = xyz(0.0, 1.0, 0.0)
rotMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
mousePosX = -1
mousePosY = -1
leftButton = False
translating = False
dolly = False
zoom = False
rq = quaternion(1, 0, 0, 0)
rq_ = quaternion(1, 0, 0, 0)
globalTranslate = xyz(0.0, 0.0, 0.0)
splinePoints1 = []
splinePoints2 = []
Exemplo n.º 31
0
 def target(self):
     from xyz import xyz, gtk
     _xyz = xyz(self.qin, self.qout, title=self.title)
     gtk.main()