1

假设我在 C++ 中有一个绘图函数来绘制这样的线条:

drawLine(float startX>, float startY, float endX, float endY);

如下图所示在旋钮周围绘制径向分布线的公式是什么:

在此处输入图像描述

好的,这段代码工作正常:

float length, x1, y1, x2, y2;
length = 40;
float radius = 80;
int sliderSteps = 8;
float rotaryStartAngle = radians(-110);
float rotaryEndAngle = radians(110);
float theta = rotaryStartAngle;
//distance between segments
float angleAmount = (rotaryEndAngle - rotaryStartAngle) / sliderSteps;

for(int i =0; i<=sliderSteps; i++){
x1 = width/2 + cos(theta)*radius;
y1 = height/2 + sin(theta)*radius;
x2 = x1+cos(theta)*length;
y2 = y1+sin(theta)*length;
theta += angleAmount;
line(x1, y1, x2, y2); 
}
4

0 回答 0