Example #1
0
    def pixel2coords(self, x, y):
        if x < 0 or x > self.pixbuf.get_width() \
        or y < 0 or y > self.pixbuf.get_height():
            return None
        if self.A is None or self.H is None or self.V is None:
            return None

        sin = math.sin(self.to)
        cos = math.cos(self.to)

        x1 = (x - self.A[0][0]) * self.dflo
        y1 = (y - self.A[0][1]) * self.dfla
        x, y = x1, y1

        x1 = x / math.sin(self.raca) + y * math.cos(self.raca)
        y1 = y
        x, y = x1, y1

        x1 = (y * sin - x * cos) / (sin*sin + cos*cos)
        y1 = (y * cos + x * sin) / (sin*sin + cos*cos)
        x, y = x1, y1

        v = Vect.vsum(Vect.vect(x1, y1), self.A[1])

        return [v[1], v[0]]
Example #2
0
    def set_ref(self, pn, x, y, la, lo):
        if   pn == "A": self.A = [ Vect.vect(x, y), Vect.vect(lo, la) ]
        elif pn == "H": self.H = [ Vect.vect(x, y), Vect.vect(lo, la) ]
        elif pn == "V": self.V = [ Vect.vect(x, y), Vect.vect(lo, la) ]
        else:
            logging.error("Bad reference point '%s'.", pn)
            return

        # check we have everything that we need before starting calculations
        if self.A is None or self.H is None or self.V is None:
            return

        logging.info("ref(A) = %f, %f" % (self.A[1][0], self.A[1][1]))
        logging.info("ref(H) = %f, %f" % (self.H[1][0], self.H[1][1]))
        logging.info("ref(V) = %f, %f" % (self.V[1][0], self.V[1][1]))

        # do calculus (we have all needed data)
        AH = Vect.vsub(self.H[1], self.A[1])
        AV = Vect.vsub(self.V[1], self.A[1])
        logging.info("vect(AH) = %f, %f" % (AH[0], AH[1]))
        logging.info("vect(AV) = %f, %f" % (AV[0], AV[1]))

        # 1) Calculate angle between an horizontal vector and 'AH' vector
        self.to = Vect.vangle2(AH, Vect.vect(1, 0))
        logging.info("angle(AH, (1,0)) = %f rad (%fº)" % (self.to, math.degrees(self.to)))

        # 2) Calculate 'raca' (angle between AH ^ AV)
        self.raca = Vect.vangle(AH, AV)
        logging.info("angle(AH, AV) = %f" % math.degrees(self.raca))

        # 3) calculate 'dflo' and 'dfla' factors (pixels to dec degrees)
        logging.info("|ha|º  = %f" % Vect.vmod(AH))
        logging.info("|ha|px = %f" % Vect.vmod(Vect.vsub(self.H[0], self.A[0])))
        logging.info("|va|º  = %f" % Vect.vmod(AV))
        logging.info("|va|px = %f" % Vect.vmod(Vect.vsub(self.V[0], self.A[0])))
        self.dflo = Vect.vmod(AH) \
                  / Vect.vmod(Vect.vsub(self.H[0], self.A[0]))
        self.dfla = Vect.vmod(AV) \
                  / Vect.vmod(Vect.vsub(self.V[0], self.A[0]))

        # 4) following printf should be always 90º
        cri = Vect.vangle(Vect.vsub(self.V[0], self.A[0]), Vect.vsub(self.H[0], self.A[0]))
        logging.info("angle(ex, ey)   = %f" % math.degrees(cri))

        self.dflo = self.dflo * math.sin(self.raca)
        self.dfla = self.dfla * math.sin(self.raca)

        logging.info("dflo = %f" % self.dflo)
        logging.info("dfla = %f" % self.dfla)