hello , I need to know how to get the direction from point A to point B

eg. point_direction(0 , 0 , 100,100); would equal 315

x1 y1 x2 y2

how do I compute this ?

Thanks !

Fbody 682 Posting Maven Featured Poster

wwsoft 0 Light Poster

what would the code be to this ?

daviddoria 334 Posting Virtuoso Featured Poster

```
#include <cmath>
#include <iostream>
int main()
{
double x1 = 0;
double y1 = 0;
double x2 = 100;
double y2 = 100;
std::cout << 180./3.14159 * atan((x2-x1)/(y2-y1)) << std::endl;
return 0;
}
```

The answer is 45 not 315 going from (0,0), to (100,100), right?

Dave

Edited by WaltP because: * Fixed CODE tags -- careful, David. Remember PREVIEW... *

rectifryer 0 Newbie Poster

Just look up the distance formula.

wwsoft 0 Light Poster

`#include <cmath> #include <iostream> int main() { double x1 = 0; double y1 = 0; double x2 = 100; double y2 = 100; std::cout << 180./3.14159 * atan((x2-x1)/(y2-y1)) << std::endl; return 0; }`

The answer is 45 not 315 going from (0,0), to (100,100), right?

Dave

well in graphics everything starts at the top left hand side :icon_smile:

daviddoria 334 Posting Virtuoso Featured Poster

Ah, yes. In mathematics the standard is +x is 0 degrees and the angle increases counter-clockwise. You'll have to adjust accordingly.

Dave

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.