日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 坐标连线_从具有和角度的坐标绘制线 - python

發(fā)布時(shí)間:2023/12/19 python 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 坐标连线_从具有和角度的坐标绘制线 - python 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我基本上想從給定角度的坐標(biāo)(x,y)繪制一條線(計(jì)算切線值)。

用這樣的簡(jiǎn)單代碼行pl.plot([x1, x2], [y1, y2], 'k-', lw=1)可以在兩點(diǎn)之間繪制一條線,但是為此我需要計(jì)算(x2,y2)坐標(biāo)。我的(x1,y1)坐標(biāo)是固定的,并且角度已知。計(jì)算(x2,y2)在某些時(shí)候會(huì)引起問題,所以我只想繪制從(x1,y1)角度(最好是長(zhǎng)度)的直線。

我想到的最簡(jiǎn)單的解決方案是使用點(diǎn)坡函數(shù)y - y1 = m(x - X1)。解釋這些并進(jìn)行一些搜索,我使用了這段代碼:

x1 = 10

y1 = -50

angle = 30

sl = tan(radians(angle))

x = np.array(range(-10,10))

y = sl*(x-x1) + y1

pl.plot(x,y)

pl.show

sl是坡度,x1和y1是坐標(biāo)。我需要自我解釋,因?yàn)檫@是一個(gè)很糟糕的問題。

所以,現(xiàn)在,關(guān)于我該如何解決的任何想法?

python大神給出的解決方案

我不確定自己從解釋中究竟想要什么,但是我認(rèn)為這將完成您所要求的工作。

如果知道要使用的線的角度和長(zhǎng)度,則應(yīng)使用三角函數(shù)獲取新點(diǎn)。

import numpy as np

import math

import matplotlib.pyplot as plt

def plot_point(point, angle, length):

'''

point - Tuple (x, y)

angle - Angle you want your end point at in degrees.

length - Length of the line you want to plot.

Will plot the line on a 10 x 10 plot.

'''

# unpack the first point

x, y = point

# find the end point

endy = length * math.sin(math.radians(angle))

endx = length * math.cos(math.radians(angle))

# plot the points

fig = plt.figure()

ax = plt.subplot(111)

ax.set_ylim([0, 10]) # set the bounds to be 10, 10

ax.set_xlim([0, 10])

ax.plot([x, endx], [y, endy])

fig.show()

總結(jié)

以上是生活随笔為你收集整理的python 坐标连线_从具有和角度的坐标绘制线 - python的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。