- 225 名前:デフォルトの名無しさん mailto:sage [2008/08/14(木) 20:37:13 ]
- 完全なソースを一応貼っておく。
#include <iostream> struct Point { double L1Point[2]; double L2Point[2]; double L1Slope; double L2Slope; double num[2]; }; Point* lineIntersect(Point* pt1); std::ostream& operator<<(std::ostream& os, const Point& pt); Point pt = {{10, 20}, {20, 44}, 10, 3, {3, 20}}; int main() { Point* ans = lineIntersect(&pt); std::cout << "答えは(" << *ans << ")です\n"; } Point* lineIntersect(Point* pt1) { pt1->num[0] = (pt1->L1Slope * pt1->L1Point[0] - pt1->L2Slope * pt1->L2Point[0] + pt1->L2Point[1] - pt1->L1Point[1]) / (pt1->L1Slope - pt1->L2Slope); pt1->num[1] = pt1->L1Slope * (pt1->num[0] - pt1->L1Point[0]) + pt1->L1Point[1]; return pt1; } std::ostream& operator<<(std::ostream& os, const Point& pt) { os << pt.num[0] << ' ' << pt.num[1]; return os; }
|

|