略有数学规划问题。 [英] Slightly mathematical programming problem.
问题描述
class Point
{
double x,y;
public:
Point (double x_,double y_):x(x_),y(y_){}
double get_x()const {return x; }
double get_y()const {return y; }
//返回0到180度之间的角度
// pre:y是非负的
double get_angle ()const;
};
double Point :: get_angle()const; // TODO:实现这个!
//返回角度最大的点
// pre:所有点都有非负y分量和点是非空的
点find_max_angle(std :: vector< Point> points)
{
Point max_point = points [0];
double max_angle = max_point.get_angle();
std :: vector< Point> :: size_type i;
for( i = 1; i< points.size(); i ++)
{
点数点=点数[i];
双角度= point.get_angle();
if(angle> max_angle)
{
max_point = point;
max_angle =角度;
}
}
返回max_point;
}
不确定如何实现Point :: get_angle。任何人的线索?
class Point
{
double x, y;
public:
Point(double x_, double y_) : x(x_), y(y_) { }
double get_x() const { return x; }
double get_y() const { return y; }
// returns an angle between 0 and 180 degrees
// pre: y is non-negative
double get_angle() const;
};
double Point::get_angle() const; // TODO: implement this!
// returns the point with greatest angle
// pre: all points have non-negative y-components and points is non-empty
Point find_max_angle(std::vector<Point> points)
{
Point max_point = points[0];
double max_angle = max_point.get_angle();
std::vector<Point>::size_type i;
for (i=1; i < points.size(); i++)
{
Point point = points[i];
double angle = point.get_angle();
if (angle > max_angle)
{
max_point = point;
max_angle = angle;
}
}
return max_point;
}
Not sure how to implement Point::get_angle. Clues anyone?
推荐答案
我想你想要找到的角度是在X轴和一条线之间
来自原点(0,0)到点(x,y)。这是正确的吗?
如果是这样,角度应为
atan(y / x)
或类似的东西。我不记得我的三角学了......
hth,
Raghu
I guess the angle you are trying to find is between X axis and a line
from the origin (0,0) to the point(x,y). Is that correct?
If so, the angle should be
atan(y/x)
or something like that. I dont remember my trigonometry well enough..
hth,
Raghu
你的意思是矢量加入原点(0,0)和点p所产生的斜率?
你可以取atan(y / x)* 180 / PI, PI => 3.14159 ......
You mean the slope made by the vector joining origin(0,0) and point p?
You can take atan(y/x) * 180 / PI, PI=>3.14159...
" Raghu Uppalli" < RA ********* @ yahoo.com>在消息中写道
news:11 ********************** @ g14g2000cwa.googlegr oups.com ...
"Raghu Uppalli" <ra*********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
我猜你试图找到的角度是在X轴和从原点(0,0)到点(x,y)的一条线之间。这是正确的吗?
如果是这样的话,角度应该是atan(y / x)
或类似的东西。我不记得我的三角函数了。
I guess the angle you are trying to find is between X axis and a line
from the origin (0,0) to the point(x,y). Is that correct?
If so, the angle should be
atan(y/x)
or something like that. I dont remember my trigonometry well enough..
我认为这不行。我需要一个0到180度之间的角度。你可以
如果你愿意,可以用弧度测量角度,但我认为度数会更好。
更清晰。
I don''t think that works. I need an angle between 0 and 180 degrees. You can
measure the angle in radians if you like but I thought degrees would be
clearer.
这篇关于略有数学规划问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!