Algorithm: how to get all points in a straight line connected by two points (how to determine whether a point is in a straight line)

Source: Internet
Author: User

Someone asked me on the snow watching forum. So I wrote this code by the way.

Q: I encountered this problem when writing code. Set the points A (100,100) and B (200,200) to a straight line. How can I get, b: All vertices in a straight line connected by two points. The brother can give a formula. Thank you first.
A: We can use the vectors to obtain the result in collinearity. I learned this in middle school:
If three points A (x1, Y1) B (X2, Y2) C (X3, Y3) are collocated, the AB CB vector is collocated. (X1 * y2-x2 * Y1) = (x1 * y3-x3 * Y1)
The following is the C language code. Compiled in tc2.1.

# Include <stdio. h>
Main ()
{
Int I;
/* A (ARR [0] [0], arr [1] [0]) B (ARR [0] [1], arr [1] [1]) */
Int arr [2] [2] ={{ 100,200 },{ 100,200 }};
/* C (arrin [0] [0], arrin [1] [0]) */
Int arrin [2] [1];
Clrscr ();
For (I = 0; I <3; I ++ ){
Printf ("Please input two interget. \ n ");
/* Input C */
Scanf ("% d", & arrin [0] [0], & arrin [1] [0]);
If (ARR [0] [0] * arrin [1] [0]-arrin [0] [0] * arr [1] [0]) = (ARR [0] [0] * arr [1] [1]-Arr [0] [1] * arr [1]

[0])
Printf ("the point C (% d) is on the line! \ N ", arrin [0] [0], arrin [1] [0]);
Else
Printf ("the point C (% d) is not on the line! \ N ", arrin [0] [0], arrin [1] [0]);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.