如何在Python中应用顺时针和逆时针的概念?

问题描述 投票:0回答:2

我是Python程序的新手,下面这张图片有两个角度(-18,27)。这些角度的符号已根据顺时针和逆时针的想法分配。如何用Python翻译这样的想法?

我的意思是顺时针和逆时针的想法。任何显示此想法的示例。

我如何在python中放置顺时针和逆时针的条件?

clockwise and counterclockwise

**This description below for the above picture:**

我们现在讨论角度范围的关键概念。 AP Theta *为每个顶点s维护两个附加值,即顶点s的下角度边界lb(s)和顶点s的上角度边界ub(s),它们共同形成角度范围[lb(s),ub (s)]。角度范围对应于起源于顶点s的射线的航向(以度为单位)。从顶点s的父级到顶点s的射线方向为零度。如果(但不一定)在以下位置包含从顶点s的父对象到顶点s的可见邻居的光线,则顶点s的可见邻居可以保证与顶点s的视线一致。顶点s的角度范围。图4.14显示了一个示例,其中顶点C3和父级A4具有角度范围[−18,27]。因此,保证红色区域中顶点C3的所有可见邻居都具有与顶点C3的父代的视线。例如,可以保证顶点C4相对于顶点C3的父级具有视线,而顶点B2则没有。因此,AP Theta *假定顶点B2与顶点C3的父级没有视线。

我们现在更正式地定义角度范围的概念。 angle(s, p, s′) ∈ [−90, 90], which gives AP Theta* its name, is the angle (measured in degrees) between the ray from vertex p to vertex s and the ray from vertex p to vertex s′. It is positive if the ray from vertex p to vertex s is clockwise from the ray from vertex p to vertex s′, zero if the ray from vertex p to vertex s has the same heading as the ray from vertex p to vertex s′, and negative if the ray from vertex p to vertex s is counterclockwise from the ray from vertex p to vertex s′.图4.14显示了一个示例,其中angle(C3,A4,C4)= 27度,而angle(C3,A4,B3)= -18度。如果(但不一定只有)角度(s,父(s),s')∈[lb(s),(但不一定),则顶点s的可见邻居s'的视线就可以保证ub]。(可见性属性)。

python
2个回答
0
投票
import numpy as np def unit_vector(vector): """ Returns the unit vector of the vector. """ return vector / np.linalg.norm(vector) def angle_between(v1, v2): """ Returns the angle in radians between vectors 'v1' and 'v2':: """ v1_u = unit_vector(v1) v2_u = unit_vector(v2) return np.rad2deg(np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0))) a4 = np.array([0,3]) c3 = np.array([2,2]) b3 = np.array([1,2]) c4 = np.array([2,3]) c4_a4 = c4 - a4 c3_a4 = c3 - a4 b3_a4 = b3 - a4 angle_b3_c3 = angle_between(c3_a4, b3_a4) angle_c3_c4 = angle_between(c3_a4, c4_a4) print angle_b3_c3 print angle_c3_c4

输出:

18.4349488229 26.5650511771

根据您必须乘以bt -1的方向才能获得顺时针或逆时针方向

0
投票
Enum

测试:

from enum import Enum


class ClockMotion(Enum):

    Clockwise = 1
    CounterClockwise = -1

    @classmethod
    def check_motion(cls, angle1, angle2):
        if angle2 - angle1 > 0:
            return cls.Clockwise
        else:
            return cls.CounterClockwise

对于顶点,使用一个简单的类,因为它将具有实例值:

>>>ClockMotion.check_motion(-30, 60)
ClockMotion.Clockwise
© www.soinside.com 2019 - 2024. All rights reserved.