- 论坛徽章:
- 14
|
回复 3# 精钢狼 - struct pt
- {
- double x;
- double y;
- };
- #include <cmath>
- pt foo( const pt& a, const pt& b, double dist )
- {
- double dt = sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
- pt c = { b.x + (b.x-a.x)/dt*dist, b.y+(b.y-a.y)/dt*dist };
- return c;
- }
- #include <iostream>
- std::ostream& operator<< ( std::ostream& os, const pt& point )
- {
- return os << '(' << point.x << ',' << point.y << ')';
- }
- #include <cassert>
- using namespace std;
- int main()
- {
- {
- pt a={71157,39267}, b={71158,39211};
- pt c = foo( a, b, 2000 );
- cout << c << endl;
- }
- return 0;
- }
复制代码 |
|