亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python中實(shí)現(xiàn)根據(jù)坐標(biāo)點(diǎn)位置求方位角

 更新時(shí)間:2023年08月16日 09:16:04   作者:邊ing  
這篇文章主要介紹了python中實(shí)現(xiàn)根據(jù)坐標(biāo)點(diǎn)位置求方位角方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

python根據(jù)坐標(biāo)點(diǎn)位置求方位角

話不多說,直接上代碼:

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout
import sys
import math
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.resize(500, 250)
        self.setWindowTitle("坐標(biāo)系")
        self.lb = QLabel("點(diǎn)1到原點(diǎn)距離:", self)
        self.lb.move(20, 40)
        self.lb2 = QLabel("點(diǎn)1與原點(diǎn)的角度:", self)
        self.lb2.move(20, 80)
        self.lb3 = QLabel("點(diǎn)2到原點(diǎn)距離:", self)
        self.lb3.move(20, 120)
        self.lb4 = QLabel("點(diǎn)2與原點(diǎn)的角度:", self)
        self.lb4.move(20, 160)
        self.bt1 = QPushButton('查詢', self)
        self.bt1.move(20, 200)
        self.edit = QLineEdit('', self)
        self.edit.move(150, 40)
        self.edit2 = QLineEdit('', self)
        self.edit2.move(150, 80)
        self.edit3 = QLineEdit('', self)
        self.edit3.move(150, 120)
        self.edit4 = QLineEdit('', self)
        self.edit4.move(150, 160)
        self.bt1.clicked.connect(self.calc_angle)
        self.show()
    def calc_angle(self):
        x1 = float(self.edit.text()) * math.cos(math.radians(int(self.edit2.text())))
        y1 = float(self.edit.text()) * math.sin(math.radians(int(self.edit2.text())))
        x2 = float(self.edit3.text()) * math.cos(math.radians(int(self.edit4.text())))
        y2 = float(self.edit3.text()) * math.sin(math.radians(int(self.edit4.text())))
        angle = 0
        dy = y2 - y1
        dx = x2 - x1
        if dx == 0 and dy > 0:
            angle = 90
            print('順時(shí)針:', angle, '°')
        if dx == 0 and dy < 0:
            angle = 270
            print('順時(shí)針:', angle, '°')
        if dy == 0 and dx > 0:
            angle = 0
            print('順時(shí)針:', angle, '°')
        if dy == 0 and dx < 0:
            angle = 180
            print('順時(shí)針:', angle, '°')
        if dx > 0 and dy > 0:
            angle = math.atan(dy / dx)* 180 / math.pi
            print('東偏北:',angle,'°')
        elif dx < 0 and dy > 0:
            angle = 90 - math.atan(dy / abs(dx))* 180 / math.pi
            print('北偏西:', angle, '°')
        elif dx < 0 and dy < 0:
            angle = math.atan(dy / dx)* 180 / math.pi
            print('西偏南:', angle, '°')
        elif dx > 0 and dy < 0:
            angle = math.atan(abs(dy) / dx)* 180 / math.pi
            print('東偏南:', angle, '°')
        length = math.sqrt(dy * dy + dx * dx)
        print(length)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

> 這里是引用

這里是引用

最后的結(jié)果之所以有那么多小數(shù)點(diǎn),是因?yàn)閙ath.pi,其實(shí)就是π,3.1415926…,有很多小數(shù)位!

其實(shí)上文就是,在一個(gè)坐標(biāo)系中,已知兩個(gè)點(diǎn)到坐標(biāo)原點(diǎn)的距離,以及它們和橫軸的角度(這都是需要自己手動(dòng)輸入的),那么就以第一個(gè)點(diǎn)為此時(shí)的坐標(biāo)原點(diǎn),求第二個(gè)點(diǎn)到第一個(gè)點(diǎn)的距離,以及第二點(diǎn)在第一點(diǎn)的相關(guān)方位。

ps:我這里是已知兩點(diǎn)到原點(diǎn)的距離和角度,就像在一個(gè)極坐標(biāo)里一樣,如果直接知道兩點(diǎn)的橫縱坐標(biāo),那么會(huì)更好求。

python根據(jù)坐標(biāo)點(diǎn)計(jì)算方位角函數(shù)

# 計(jì)算方位角函數(shù)
def azimuthAngle( x1, y1, x2, y2):
  angle = 0.0;
  dx = x2 - x1
  dy = y2 - y1
  if x2 == x1:
    angle = math.pi / 2.0
    if y2 == y1 :
      angle = 0.0
    elif y2 < y1 :
      angle = 3.0 * math.pi / 2.0
  elif x2 > x1 and y2 > y1:
    angle = math.atan(dx / dy)
  elif x2 > x1 and y2 < y1 :
    angle = math.pi / 2 + math.atan(-dy / dx)
  elif x2 < x1 and y2 < y1 :
    angle = math.pi + math.atan(dx / dy)
  elif x2 < x1 and y2 > y1 :
    angle = 3.0 * math.pi / 2.0 + math.atan(dy / -dx)
  return (angle * 180 / math.pi)
#計(jì)算角度
print(white_point)
if white_point[0][0]>white_point[1][0]:
    x1=white_point[1][0];
    y1=white_point[1][1];
    x2=white_point[0][0];
    y2=white_point[0][1];
else:
    x1=white_point[0][0];
    y1=white_point[0][1];
    x2=white_point[1][0];
    y2=white_point[1][1];
angle = 90-azimuthAngle(x1,y1,x2,y2)
print("angle:"+str(angle))

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論