计算机图形学画线
计算机图形学| 直接使用线方程 (Computer Graphics | Direct Use of Line Equation)
The standard line equation, as we all know is used for drawing a line. It is given by: y = mx + c.
众所周知,标准线方程式用于绘制线。 由下式给出: y = mx + c 。
We are discussing here in 2D so we all know that there are 2 axes: x and y. Both of the axes are required to give the equation of any 2D shape. The line is a straight path joining 2 points in the x-y plane. If both the points are given then we can find the equation of a line.
我们在这里以2D进行讨论,所以我们都知道有2个轴: x和y 。 需要两个轴都可以给出任何2D形状的方程。 该线是连接xy平面中2个点的直线路径。 如果两个点都给出,那么我们可以找到一条线的方程。
直线的斜率 (The slope of a line)
The slope of a line defines the direction of a line. Its value is equal to the ratio of the difference of y coordinates and the difference. Assume that the two points are X( x1,y1 ) and Y( x2,y2 ). Its slope, 'm' will be: m = (y2 - y1) / (x2 - x1).
线的斜率定义了线的方向。 它的值等于y坐标差与差之比。 假设这两个点是X(x1,y1)和Y(x2,y2) 。 它的斜率'm'将是: m =(y2-y1)/(x2-x1) 。
线描算法的性质 (Properties of Line Drawing Algorithm)
The following are the properties that a line must hold in any line drawing algorithm,
以下是任何线图绘制算法中线必须具有的属性,
Line must be straight
线必须是直的
Line must terminate accurately
线路必须准确终止
Line must have constant density
线必须具有恒定的密度
Density must be independent of its length
密度必须与长度无关
Line must be drawn very fast
线必须画得很快
线描算法 (Line Drawing Algorithms)
There are some set of rules and steps which help draw a line. These algorithms are given below,
有一些规则和步骤可以帮助您划清界限。 这些算法如下:
Direct Use of line equation
直接使用线方程
DDA (Digital Differential Analyzer)
DDA(数字差分分析仪)
Bresenham's Algorithm
布雷森纳姆算法
直接使用线方程 (Direct use of Line Equation)
This is the simplest form of drawing a line. We all know that the equation of the line is y = mx + c. Here m is slope and c is the length from origin to the point where the line cuts y-axis. In this method, we will be having the start and endpoint of the line and by the help of that points, we'll calculate the other points which lie on the line. We have to find the slope of the line by using the given points.
这是画线的最简单形式。 我们都知道直线的方程是y = mx + c 。 这里的m是斜率, c是从原点到直线切割y轴的点的长度。 在这种方法中,我们将获得直线的起点和终点,并借助这些点,计算出直线上的其他点。 我们必须使用给定的点找到线的斜率。
We'll understand this better with the help of an example,
我们将通过一个示例来更好地理解这一点,
Example:
例:
We have given two points X and Y. The coordinates of X are (0, 0) and the coordinates of Y are (5, 15). The slope of the line will be,
我们给出了X和Y两点。 X的坐标为(0,0) , Y的坐标为(5,15) 。 线的斜率是
m = (15 - 0) / (5-0)
m = 3
We have the slope of the line. Now let us put the slope in the line equation.
我们有直线的斜率。 现在让我们将斜率放在线方程中。
y = 3x + c
Origin point is (0,0). So,
原点是(0,0)。 所以,
c = 0
Putting c=0 in the above equation.
将c = 0放在上式中。
y = 3x
Now we will calculate the intermediate points.
现在我们将计算中间点。
Let x = 1 ⟹ y = 3 x 1 ⟹ y = 3
Let x = 2 ⟹ y = 3 x 2 ⟹ y = 6
Let x = 3 ⟹ y = 3 x 3 ⟹ y = 9
Let x = 4 ⟹ y = 3 x 4 ⟹ y = 12
Let x = 5 ⟹ y = 3 x 5 ⟹ y = 15
We got the intermediate points which are, (1, 3), (2, 6), (3, 9), (4, 12) and finally (5, 15)
我们得到的中间点是(1、3),(2、6),(3、9),(4、12),最后是(5、15)
Now we'll plot these points on the graph.
现在,我们将这些点绘制在图形上。
Hence, we have plotted the points that lie between the given points through the standard line equation. By doing so with a very small gap between these pints will give us the entire line.
因此,我们通过标准线方程式绘制了位于给定点之间的点。 这样,这些品脱之间的间隙很小,就可以给我们整条生产线。
翻译自: https://www.includehelp.com/computer-graphics/direct-use-of-line-equation.aspx
计算机图形学画线