Clockwise or Counterclockwise(八,学习总结)

本文介绍了一种使用向量计算的方法来判断由三个等距于原点的点构成的圆是顺时针还是逆时针方向形成的。通过计算向量AB和AC的叉乘结果,可以快速判断出圆的方向。

在这里插入图片描述
题意:给三个点A,B,C,三点到原点距离相等,从A到B再经过C来形成圆,问该圆是逆时针还是顺时针形成。

思路:用向量来解决,选择向量AB和AC,若AB✖C小于0,则为逆时针形成,否则为顺时针形成。

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
	int tcase;
	cin>>tcase;
	while(tcase--){
		ll x1,y1,x2,y2,x3,y3;
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		if((x3-x1)*(y2-y1)-(y3-y1)*(x2-x1)<0){
			cout<<"Counterclockwise"<<endl;
		}
		else{
			cout<<"Clockwise"<<endl;
		}
	}
	return 0;
}
7-168 Dream to EC-Final 分数 20 作者 吕佳霖 单位 中国计量大学 ICPC Asia East Continent Final, one of the oldest, largest, and most prestigious programming competitions in China, is attracting more and more competitors from all over the country to participate in, including CJLUACMers. Moreover, it's a huge dream for most of them. During these years, the EC-Final was always hosted by Northwestern Polytechnical University (NWPU) in Xi'an City, Shann Xi Province. (Reference: http://m.haiwainet.cn/middle/3542417/2019/1218/content_31684163_1.html) As a competitor of ICPC EC-Final in 2019, Derrick took part in this programming competition and visited Xi'an City. However, Derrick had another dream that would be never come true, which was travelling in the ancient Xi'an City in Tang Dynasty. 微信图片_20210307183647(1).jpg In order to discover the landscape of the ancient Xi'an City, Derrick has already searched enough information about it. Just as Hundreds and Thousands of houses are like a Go game, and twelve streets are like a vegetable garden(百千家似围棋局,十二街如种菜畦)written by Juyi Bai. This poetry vividly demonstrates the structure of the ancient Xi'an City, it consists of several vertical streets and horizontal roads of the same lengths but different widths. Supposed that the shape of whole city is an n×n square, which composed of n vertical streets x 1 ​ , x 2 ​ ,..., x n ​ and n horizontal roads y 1 ​ , y 2 ​ ,..., y n ​ within the same lengths and different widths from centre. Derrick is curious about calculating the area of all intersections, because he wants to calculate the traffic flow accurately at each intersection in the ancient Xi'an City. However, Derrick considers this task is quite easy for you, so Derrick will spin the whole square with 45 degree at first, maybe clockwise or maybe counterclockwise. After that, you are asked to calculate the total area of all intersections for each row and each column. Input Specification: There are multiple test cases. The first line of the input contains an integer T, indicating the number of test cases. For each test case: The first line contains two integers n (1≤n≤1000) and d, indicating the size of the square and the direction of rotating the square. When d=1, it means that the direction of rotation is clockwise. When d=0, it means that the direction of rotation is counterclockwise. The second line contains n integers x 1 ​ , x 2 ​ ,..., x n ​ (0≤x i ​ ≤5×10 4 ), indicating the width of vertical streets at the i-th position from centre. The third line contains n integers y 1 ​ , y 2 ​ ,..., y n ​ (0≤y j ​ ≤5×10 4 ), indicating the width of horizontal roads at the j-th position from centre. It's guaranteed that the sum of n of all test cases will not exceed 2×10 4 . Output Specification: For each case, in the first line output 2n−1 integers separated by a space, indicating the total area of intersections for each row after rotating 45 degree. Similarly, in the second line print 2n−1 integers separated by a space, indicating the total area of intersections for each column after rotating 45 degree. Note: Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect! Sample Input: 1 3 0 1 2 3 3 2 1 Sample Output: 3 8 14 8 3 1 4 10 12 9 Hint: For example, the initial state of 3×3 square, the clockwise state of 3×3 square and the counterclockwise state of 3×3 square are shown as the following, respectively: 微信图片_20210307204029.png给出C代码
09-20
### AB编码器在NVIDIA Orin平台上的使用或配置 AB编码器是一种常见的位置传感器,通常用于测量旋转轴的角度和速度。在NVIDIA Orin平台上使用AB编码器涉及硬件连接、驱动程序设置以及软件接口开发等多个方面。 #### 硬件准备 为了使AB编码器能够在Orin平台上正常工作,需确保其信号线(A相、B相和可能的Z相零位脉冲)已正确连接到支持外部中断输入的GPIO引脚上。具体来说,在设计电路板时应考虑以下几点[^1]: - **选择合适的GPIO引脚**: 需要挑选能够触发边沿检测事件的通用I/O口作为接收端。 - **电源匹配与隔离保护措施**: 编码器供电电压范围一般为5V或者3.3V, 要确认所选微控制器单元(MCU)能承受该电平;另外加装光电耦合器件可以有效防止噪声干扰并提高可靠性。 完成上述物理层准备工作之后,则进入操作系统层面的操作流程: #### 设备树修改 由于Linux内核通过Device Tree描述嵌入式系统的硬件资源分配情况,因此当新增外设如本案例中的增量型光栅尺(即AB编码器),就需要编辑相应的`.dts`文件来定义这些新加入组件的相关属性参数。对于基于ARM架构运行Ubuntu操作系统的Jetson系列模块而言,可以通过创建自定义overlay实现动态加载功能而无需重新编译整个kernel image: ```bash sudo mkdir /sys/kernel/config/device-tree/overlays/ab_encoder sudo sh -c "cat ab_encoder.dtbo > /sys/kernel/config/device-tree/overlays/ab_encoder/dtbo" ``` 这里假设已经制作好了一个名为`ab_encoder.dtbo`的预构建二进制blob对象,它包含了针对特定型号AB编码器所需的全部必要信息比如pinmux设定等等。 一旦成功应用此更改后,就可以继续下一步骤了——编写应用程序读取来自指定通道的数据流。 #### 用户空间编程实例 下面给出了一段简单的Python示范代码片段展示如何利用RPI.GPIO库监听由AB编码器产生的方向变化通知事件: ```python import RPi.GPIO as GPIO import time ENCODER_A_PIN = 7 # Replace with actual pin number used for A phase signal ENCODER_B_PIN = 8 # Replace with actual pin number used for B phase signal position = 0 # Initialize position counter to zero def update_position(channel): global position a_state = GPIO.input(ENCODER_A_PIN) b_state = GPIO.input(ENCODER_B_PIN) if (a_state and not b_state): # Clockwise rotation detected position += 1 elif (not a_state and b_state): # Counterclockwise rotation detected position -= 1 print(f'Current Position: {position}') try: GPIO.setmode(GPIO.BCM) GPIO.setup(ENCODER_A_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(ENCODER_A_PIN, GPIO.RISING, callback=update_position) while True: time.sleep(0.1) # Keep main thread alive waiting for interrupts finally: GPIO.cleanup() # Cleanup all resources before exiting program safely. ``` 注意以上例子仅适用于基础测试目的,并未考虑到实际工业环境中可能出现的各种复杂情形例如抖动过滤机制等问题。如果项目需求较高精度控制的话建议采用专门设计好的FPGA/CPLD方案替代纯SW解决方案以获得更佳性能表现[^2].
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值