简体   繁体   English

如何找到一个点的坐标,使其与给定的线成 135 度角?

[英]How to find the coordinates of a point such that it makes a 135 degree angle with a given line?

Given a line segment uv I want to find the coordinates of point x such that they make up an angle of 135 degrees with a given distance of L , below is an illustration:给定一条线段uv我想找到点x的坐标,使它们与给定的距离L组成一个 135 度的角,下面是一个说明:

样本

I would use a triangle to determine where x is, you can use a 45 45 90 triangle because the angle is 135 degrees.我会使用三角形来确定 x 在哪里,你可以使用 45 45 90 三角形,因为角度是 135 度。 If it was not 135 degrees you can use sin and cos to find x如果不是 135 度,您可以使用 sin 和 cos 来找到 x

在此处输入图片说明

Find uv vector as找到uv向量为

uv.x = v.x - u.x
uv.y = v.y - u.y

Calculate its length计算其长度

luv = sqrt(uv.x * uv.x + uv.y * uv.y)

Find point at continuation of uv line with distance L from v :uv线与v距离为L延续处找到点:

px = v.x + L * uv.x  / luv
py = v.y + L * uv.y  / luv

Rotate this point around v by 45 degrees ( Pi/4 ):将此点绕v旋转 45 度 ( Pi/4 ):

qx = v.x + (p.x - v.x) * cos(Pi/4) - (p.y - v.y) * sin(Pi/4)
qy = v.y + (p.x - v.x) * sin(Pi/4) + (p.y - v.y) * cos(Pi/4)

Note that we can simplify tha last expressions a bit using coordinate difference请注意,我们可以使用坐标差来简化最后一个表达式

rx = L * uv.x  / luv
ry = L * uv.y  / luv

Rotate this point around v by 45 degrees ( Pi/4 ):将此点绕v旋转 45 度 ( Pi/4 ):

qx = v.x + rx * cos(Pi/4) - ry * sin(Pi/4)
qy = v.y + rx * sin(Pi/4) + ry * cos(Pi/4)

Also both cos(Pi/4) and sin(Pi/4) are equal to sqrt(2)/2 , so you can use this constant if you don't need different angles.此外, cos(Pi/4)sin(Pi/4)都等于sqrt(2)/2 ,因此如果您不需要不同的角度,则可以使用此常量。

Actually, you don't have to calculate all the math by yourself.实际上,您不必自己计算所有数学运算。 There are several libraries for geometric computation that offer functionality to perform the task in just a couple of lines of code.有几个用于几何计算的库提供了只需几行代码即可完成任务的功能。

For example, Shapely has rotate and scale functions that could be used here:例如, Shapely具有可以在此处使用的rotatescale功能:

from shapely.geometry import LineString
from shapely.affinity import rotate, scale

uv = LineString([(0, 0), (1, 0)])
vx_length = 2
pivot_point = uv.boundary[1]
scale_factor = vx_length / uv.length
uv_rotated = rotate(uv, -135, origin=pivot_point)
vx = scale(uv_rotated, 
           xfact=scale_factor,
           yfact=scale_factor,
           origin=pivot_point)
print(vx)
# LINESTRING (2.414213562373095 1.414213562373095, 1 0)
print(vx.length)
# 2.0

在此处输入图片说明

Note that we should give the negative angle to rotate since by default rotation is performed counterclokwise but we need it to be clockwise.请注意,我们应该给rotate负角度,因为默认情况下旋转是逆时针执行的,但我们需要它是顺时针的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python - 我怎样才能找到一条线在给定点的角度? - Python - how can i find the angle of a line at a given point? 如何在python中给定点(x,y)和线与y轴的夹角的情况下找到线的斜率(m)? - How do I find the slope (m) for a line given a point (x,y) on the line and the line's angle from the y axis in python? 计算直线的角度(度) - Calculate angle (degree) of a straight line 通过角度和长度计算线的端点坐标 - Calculate coordinates of end point of a line by having the angle and the length 找出一点占线的百分比 - Find what percent of a line a point makes up python用弧度找到x,y坐标,给定角度 - python find x,y coordinates with radian, angle given 如何在给定线的另一个点和垂直线上的2个点的线上找到点的X坐标? - How to find the X coordinate of a point on a line given another point of the line and the 2 points on a perpendicular line? 在道路网络坐标列表上找到最接近给定点的点 - Find the closest point on a road network coordinates list to a given point 如何找到从附近点到 3D 线的截点坐标? - How to find coordinates of intercept point from a nearby point to a line in 3D? 根据随机点求两条相连线段的角度 - Find the angle of two connected line segments based upon a random point
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM