寻找最大距离 [英] Find largest distance
问题描述
我遇到了一个问题,需要我想出一种方法来计算不同形状的最大边周长。我对如何开始使用它感到困惑。
这是一些代码。
公共类PerimeterAssignmentRunner {
public double getPerimeter(Shape s){
double totalPerim = 0.0;
点prevPt = s.getLastPoint();
for(Point currPt:s.getPoints()){
double currDist = prevPt.distance(currPt);
totalPerim = totalPerim + currDist;
prevPt = currPt;
}
// totalPerim就是答案
return totalPerim;
}
包裹提供了另一个文件中给出的点数(不知道确切的术语)。
我尝试过:
double largestSide = 0 ;
点prevPt = s.getLastPoint();
for(Point currPt:s.getPoints())
Hi, I am stuck on a problem that requires me to come up with a way to calculate the largest side perimeters of different shapes. I am kind of confused on how to even start with it tbh.
This is some of the code.
public class PerimeterAssignmentRunner {
public double getPerimeter (Shape s) {
double totalPerim = 0.0;
Point prevPt = s.getLastPoint();
for (Point currPt : s.getPoints()) {
double currDist = prevPt.distance(currPt);
totalPerim = totalPerim + currDist;
prevPt = currPt;
}
// totalPerim is the answer
return totalPerim;
}
The package was provided with points given in another file (don't know the exact the terminology).
What I have tried:
double largestSide = 0;
Point prevPt = s.getLastPoint();
for(Point currPt:s.getPoints())
推荐答案
计算每个部分的长度,即基本的毕达哥拉斯: BBC - GCSE Bitesize :线段的长度 [ ^ ]
然后你所要做的就是锻炼时间最长......
Work out the length of each segment, that is basic Pythagoras: BBC - GCSE Bitesize: The length of a line segment[^]
Then all you have to do is work out the longest...
这篇关于寻找最大距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!