C++计算圆柱体的算法

#include<iostream>
using namespace std;
#define PI 3.14
class CCylinder
{
public :
	CCylinder()
	{
		m_iRadius=0;
		m_iHeight=0;
	}
	CCylinder(int iRadius,int iHeight)
	{
		m_iRadius=iRadius;
		m_iHeight=iHeight;
	}
	int getArea()
	{
		return PI*m_iRadius*m_iRadius*m_iHeight;
	}
	void setRadius(int iRadius)
	{
		m_iRadius=iRadius;
	}
	void setHeight(int iHeight)
	{
		m_iHeight=iHeight;
	}
	int getRadius()//无法直接输出,所以间接地
		            //通过函数来输出
	{
		return m_iRadius;
	}
	int getHeight()
	{
		return m_iHeight;
	}
protected://保护对象,不会被外面更改
	int m_iRadius;
	int m_iHeight;
};
int main()
{
	CCylinder cld;
	int i,j;
	cout << "输入圆柱的半径" << endl;
		cin >> i;
		cld.setRadius(i); //设置圆柱的半径
	cout << "输入圆柱的高度" << endl;
		cin >> j;
		cld.setHeight(j); //设置圆柱的高
	cout << "圆柱的半径为:" << cld.getRadius()<<endl;
	cout << "圆柱的高度为:" << cld.getHeight()<< endl;
	cout << "圆柱的体积为:" << cld.getArea()<< endl;
	return 1;
}


  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
OpenCV是一个开源的计算机视觉库,可以进行图像处理和计算机视觉任务。如果你想在C++中使用OpenCV来处理球形、立方体和圆柱体,以下是一些示例代码: 1. 球形检测: ```cpp #include <opencv2/opencv.hpp> int main() { cv::Mat image = cv::imread("ball.jpg"); // 读取球形图像 cv::Mat grayImage; cv::cvtColor(image, grayImage, cv::COLOR_BGR2GRAY); // 将图像转换为灰度图像 cv::HoughCircles(grayImage, circles, cv::HOUGH_GRADIENT, 1, grayImage.rows / 8, 200, 100, 0, 0); // 使用霍夫圆变换检测球形 for (size_t i = 0; i < circles.size(); i++) { cv::Vec3f circle = circles[i]; cv::Point center(circle[0], circle[1]); int radius = circle[2]; cv::circle(image, center, radius, cv::Scalar(0, 0, 255), 2); // 在图像中画出检测到的球形 } cv::imshow("Detected Circles", image); cv::waitKey(0); return 0; } ``` 2. 立方体检测: 对于立方体的检测,可以使用3D点云库(例如PCL)或深度学习方法进行。 3. 圆柱体检测: ```cpp #include <opencv2/opencv.hpp> int main() { cv::Mat image = cv::imread("cylinder.jpg"); // 读取圆柱体图像 cv::Mat grayImage; cv::cvtColor(image, grayImage, cv::COLOR_BGR2GRAY); // 将图像转换为灰度图像 cv::Mat edges; cv::Canny(grayImage, edges, 50, 150); // 边缘检测 std::vector<cv::Vec4i> lines; cv::HoughLinesP(edges, lines, 1, CV_PI / 180, 50, 50, 10); // 使用霍夫直线变换检测圆柱体的竖直边缘 for (size_t i = 0; i < lines.size(); i++) { cv::Vec4i line = lines[i]; cv::line(image, cv::Point(line[0], line[1]), cv::Point(line[2], line[3]), cv::Scalar(0, 0, 255), 2); // 在图像中画出检测到的竖直边缘 } cv::imshow("Detected Lines", image); cv::waitKey(0); return 0; } ``` 以上代码示例只是简单的演示,具体的实现方法可能因为你的场景和图像而有所不同。你可能需要根据具体情况对参数进行调整,并进行更复杂的图像处理和计算机视觉算法。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

袁博特

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值