파이썬에서 다른 선의 끝점에서 수직선을 그리는 방법은 무엇입니까? [복제]
Nov 15 2020
주어진 길이에 대해 종점에서 현재 선분에 직각 / 수직 인 선분을 그리려고합니다. 여기에 문제를 더 잘 설명하는 데 도움이되는 그림이 있습니다.

line a
좌표와 임의의 값이 주어지면 length
선분 b
및 의 좌표를 찾고 싶습니다 (x3,y3)
.
도움을 주셔서 감사합니다.
업데이트 : 여기 에서 내 솔루션 을 찾아 Python에 적용했습니다. mods는 이것을 중복으로 표시하고 닫으십시오.
답변
1 narayanavamseeKolluru Nov 16 2020 at 05:51
나는 sympy 모듈을 사용하고 얻는 것이 쉬울 것이라고 생각합니다.
import sympy.geometry as gm
line1=gm.Line(gm.Point(1,2),gm.Point(5,4))
line2=line1.perpendicular_line(line1.p2)
line1- 초기 선입니다 (방정식 --2 x + 4 y-6) line2-는 끝점 (5,4)에 그려진 수직선입니다 (방정식 --4 x-2 y + 28).
제발 봐주세요 https://docs.sympy.org/latest/modules/geometry/lines.html 선분에 대해 자세히 설명합니다.
1 HumbleBee Nov 15 2020 at 12:29
나는 여기 C #에서 답을 찾았고 여기 에 누군가가 관심이있는 경우에 대비 한 파이썬 코드가 있습니다.
import math
# sample line and length
line_a = ([4, 4], [2, 2])
length = 2
initial_pt_x = line_a[0][0]
initial_pt_y = line_a[0][1]
terminal_pt_x = line_a[1][0]
terminal_pt_y = line_a[1][1]
dx = initial_pt_x - terminal_pt_x
dy = initial_pt_y - terminal_pt_y
perp_angle = math.atan2(dy, dx)
x = terminal_pt_x + math.sin(perp_angle) * length
y = terminal_pt_y - math.cos(perp_angle) * length
# For the opposite direction
x = terminal_pt_x - math.sin(perp_angle) * length
y = terminal_pt_y + math.cos(perp_angle) * length