c++中的三角函数

C++三角函数和反三角函数 并且它们在处理特殊情况(例如超出定义域的值)时可能返回特殊值,如 NaN(非数字)或正负无穷大。在实际使用中,确保输入的值在定义域范围内,并注意处理可能的异常情况。头文件中,因此需要包含该头文件以在程序中使用它们。这些函数接受弧度或角度作为参数,具体取决于函数的实现。在使用之前,可能需要将角度转换为弧度,例如通过乘以。当涉及到三角函数和反三角函数时,C++提供了一组函数来执行这些计算。三角函数的返回值类型为。来将角度转换为弧度。 阅读详情
AI摘要

本文介绍了如何使用C++编程语言来计算正弦(sin), 余弦(cos)和正切(tan)的基本运算,并通过实例展示了如何在`main()`函数中接收用户输入并输出结果。这对于初学者理解和实践三角函数在计算机科学中的应用很有帮助。

相信大家学三角函数时都会非常头疼。

三角函数 f(x)=sinxf(x) = sinxf(x)=sinx 图像:
在这里插入图片描述
那么c++可以帮助你解决。

1. sin

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	cout<<sin(n);
	return 0;
}

2. cos

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	cout<<cos(n);
	return 0;
}

3. tan

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	cout<<tan(n);
	return 0;
}
C++ 中三角函数:sin,cos,asin,acos等   在C++中调用数学函数时,需包含头文件#Include<math.h>   C++中三角函数操作的是弧度,而不是角度。所以进行计算时需要将角度转化为弧度。   弧度=角度*Pi/180; 常用函数: abs绝对值函数 acos反余弦函数 asin反正弦函数 atan反正切函数 exp e的x次方 cos余弦函数 sin正弦函数 tan正切函数 ceil求不小于x的最小整数 cosh求x的双曲余弦值 fabs求浮点数x的绝对值 fmod计算x/y的余数 frexp把浮点数x分解成尾数和指数 阅读详情

相关推荐

C++三角函数实战:从基础应用到游戏开发中的角度计算

本文深入探讨了C++三角函数在游戏开发中的实战应用。文章将sin、cos等函数比作“角度翻译官”,详细讲解了如何利用它们实现角色任意方向移动、物体绕点旋转以及使用atan2函数精准计算两点间角度等核心游戏逻辑。同时,针对性能优化和常见开发“坑点”提供了实用建议,帮助开发者高效地将数学工具应用于游戏世界构建。

weixin_27943395的博客 239

C++实现三角函数

c++中关于三角函数的使用

m0_64182150的博客 1万+

C++游戏开发实战:三角函数与反三角函数在角色移动中的5种妙用

本文深入探讨了C++游戏开发中三角函数与反三角函数的实战应用,重点解析了其在角色移动、镜头控制与物理模拟中的5种核心技巧。内容涵盖圆周运动、抛物线轨迹、平滑旋转、波形动画及方向计算,并提供了性能优化与常见陷阱的解决方案,帮助开发者高效实现复杂的游戏运动逻辑。

weixin_29009669的博客 381

C++中使用三角函数:入门指南(sin、cos、tan、atan)

C++三角函数用法

Eason_jun的博客 1万+

C++标准库中的三角函数与反三角函数详解

本文介绍了C++标准库<cmath>中的三角函数和反三角函数。主要内容包括:基本三角函数(sin,cos,tan)的功能、定义域和值域;反三角函数(asin,acos,atan)的使用方法;四象限反正切函数atan2的特点;以及浮点精度和特殊值处理的注意事项。文章还提供了实际应用示例,如直角三角形计算、坐标转换等,并给出了性能优化建议。所有函数均使用弧度制,需注意定义域限制和浮点精度问题。这些函数在图形学、物理模拟等领域有广泛应用,是C++数学计算的重要基础工具。

专注现代C++实战,从核心语法到高性能编程,助力开发者深入掌握系统级编程精髓。 291

C++写的三角函数

C++三角函数的应用提供各种函数在C++中的应用

浅谈三角函数在C++中的使用

首先定义一下π const int pai = 3.14159265358979323; sin(double); double是指弧度值,也就是30度需转换为π/6, sin(pai/6); 当你输入度数时,例如30度,需要这样操作 sin((30.0*pai)/180.0); //值为0.5 而当你知道0.5想求度数的时候,自然想到反三角函数,但是求出来的仍是弧度值,所以需要以下操作 ...

TSWorld 3315

`全网最细!! 入门必看Git教程链接:https://gitee.com/all-about-git`

全网 Git 入门教程 gitee.com。如果显示The requested URL returned error: 403错误,那就表示没有和window本地建立token令牌

qq_37855368的博客 3747

c++ 三角函数_前端程序员必须掌握之三角函数在前端动画中的应用

开发过程中经常有意无意地刻意避开数学相关的知识,你也知道解数学题非常枯燥无趣。平时写动画也尽量使用 css3 来实现,timer-function 随意选用,最多也就调一下cubic-bezier,找到看着舒服的就行。但是怎样让动画更顺滑,写出更贴近自然的动画,说实话以前我没怎么考虑过。每次当动效设计师提出,能不能这样那样的时候,我会理所当然地予以否决。所以有很长一段时间,我非常羡慕那些能用 ca...

weixin_29585583的博客 389

VConsole动态加载

// 移动端真机调试工具 vconsole import VConsole from "vconsole"; import Vue from "vue"; // 动态使用VConsole if(process.env.NODE_ENV==='production'){ if(process.env.VUE_APP_BASEURL.includes('test')||process.env.VUE_APP_BASEURL.includes('pre')){ Vue.prototype

aliven1的博客 1041

Windows系统3D Gaussian Splatting环境搭建全攻略:从零开始到成功运行

本文详细介绍了在Windows系统上搭建3D Gaussian Splatting环境的完整流程,包括CUDA 12.6安装、Anaconda环境配置、代码获取与依赖安装等关键步骤。针对Windows平台特有的环境配置问题,提供了实用的解决方案和常见错误排查方法,帮助开发者快速实现3D Gaussian Splatting的成功运行。

weixin_30832143的博客 452

c++中math头文件中的三角函数

/* cos example */ #include <stdio.h> /* printf */ #include <math.h> /* cos */ #define PI 3.14159265 int main () { double param, result; param = 60.0; result = cos ( param ...

zhoulib__的博客 5365

ElaticSearchUtil工具类封装

package com.xxx.util; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction; import org.elasticsearch.action.ad

会飞的狼 6295

c++想用三角函数_前端程序员必须掌握之三角函数在前端动画中的应用

开发过程中经常有意无意地刻意避开数学相关的知识,你也知道解数学题非常枯燥无趣。平时写动画也尽量使用 css3 来实现,timer-function 随意选用,最多也就调一下cubic-bezier,找到看着舒服的就行。但是怎样让动画更顺滑,写出更贴近自然的动画,说实话以前我没怎么考虑过。每次当动效设计师提出,能不能这样那样的时候,我会理所当然地予以否决。所以有很长一段时间,我非常羡慕那些能用 ca...

weixin_39801714的博客 137

RK3588开发笔记-MIPI-CSI接口视频解码芯片XS9922B调试

Rockchip RK3588 是一款高性能的处理器,支持多种摄像头接口,包括 MIPI(Mobile Industry Processor Interface)接口。MIPI是一种用于移动设备和嵌入式系统中的摄像头、显示器和其他传感器设备的串行接口标准。MIPI是MIPI联盟发起的为移动应用处理器制定的开放标准。CSI-2(Camera Serial Interface 2)是MIPI 联盟定义的另一种高速接口,主要用于摄像模组和处理器之间的连接。

flypig has a dream! 6860

LeRobot 入门教程(五)异步推理

本文介绍了基于SmolVLA的异步推理技术在机器人控制中的应用。通过将动作预测与执行解耦,异步推理消除了传统同步推理中的等待延迟,使机器人行为更加流畅。文章详细讲解了如何安装依赖、启动策略服务器和机器人客户端,并重点说明了关键参数actions_per_chunk和chunk_size_threshold的调整方法。实验表明,异步推理能显著提升机器人响应速度,特别适合大规模模型应用。最后,文章建议用户根据具体硬件和任务需求优化参数配置,以获得最佳性能。

2506_90492529的博客 1643

lua/c++中的三角函数与反三角函数,操作的是弧度非角度

c++中cos,sin,asin等等这些三角函数操作的是弧度,而非是角度,需要把角度转换为弧度。 -- 参考 https://blog.youkuaiyun.com/yu121380/article/details/80410854 function testMath() -- 弧度=角度*pi/180; -- 角度=弧度*180/pi; print(math.sin(30 * math.pi / 1...

eclipse_c 的专栏 3179

【四足机器人项目实战】四足机器人弹簧倒立摆(SLIP)动力学模型

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录系列文章目录前言1.动力学建模构型方法2.四足机器人动力学模型(1)多体动力学模型【针对躯干+脚建模】方法一:VMC(VirtualModelController)模型方法二:SLIP模型(2)浮基单体动力学模型【针对躯干建模】【用于MPC】 前言 认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长! 本文先对四足机器人动力学模型-VMC、SLIP和浮动机体模型做个简

qq_35635374的博客 7310

c++ 绘制函数图像_前端程序员必须掌握之三角函数在前端动画中的应用

开发过程中经常有意无意地刻意避开数学相关的知识,你也知道解数学题非常枯燥无趣。平时写动画也尽量使用 css3 来实现,timer-function 随意选用,最多也就调一下 cubic-bezier,找到看着舒服的就行。但是怎样让动画更顺滑,写出更贴近自然的动画,说实话以前我没怎么考虑过。每次当动效设计师提出,能不能这样那样的时候,我会理所当然地予以否决。所以有很长一段时间,我非常羡慕那些能用 c...

weixin_39913141的博客 588

基于YOLO26的实时目标追踪实战:从训练到视频追踪(附完整可视化代码)

核心组合:YOLO26(高精度检测)+ ByteTrack(稳定追踪)是实时目标追踪的最优工业组合,Ultralytics内置集成无需额外开发;训练优化:追踪场景需优先提升检测框精度(增加box损失权重),保证ID稳定性;可视化核心:为每个ID分配唯一颜色、绘制运动轨迹、显示FPS,是落地场景的必备功能;性能调优:轻量化模型+降分辨率+OpenVINO导出,可在边缘设备(如研华工控机)实现实时追踪。这套代码可直接复用到智慧园区、停车场、工业产线等场景,仅需修改park.yaml中的类别和。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 571

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

C++三角函数实战指南:从弧度转换到游戏开发中的sin、cos、atan2应用

在C++编程中,三角函数是处理角度计算、方向向量和几何变换的基础工具。其核心原理基于弧度制,通过sin、cos、tan等函数实现坐标与角度的相互转换。掌握这些函数不仅能解决图形旋转、碰撞检测等工程问题,还能提升游戏开发、物理模拟等场景的代码效率。例如,在2D游戏中,利用atan2计算朝向角度,结合sin和cos生成移动向量,可轻松实现鼠标跟随或子弹追踪。本文聚焦C++标准库中的三角函数,详解弧度转换、atan2参数顺序及常见精度陷阱,帮助初学者快速上手实际项目。

weixin_33971977的博客 184

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

栈内存 ,堆内存区别 C++ 动态内存 == 与equal区别 复合函数奇偶性 三角函数转换公式: 虚函数和纯虚函数: C++ 中的运算符重载 数据封装,数据抽象 C++ 接口(抽象类

栈内存:在函数中定义的一些基本类型的变量和对象的引用变量都在函数的栈内存中分配,存取速度比堆要快,仅次于直接位于CPU中的寄存器。但缺点是,存在栈中的数据大小与生存期必须是确定的,缺乏灵活性。 堆内存:用来存放由new创建的对象和数组。在堆中分配的内存,由Java虚拟机的自动垃圾回收器来管理。 C++动态内存 栈:在函数内部声明的所有变量都将占用栈内存。 堆:这是程序中未使用的内存,在...

ZhangJiqun&191cm&85kg 956

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

C/C++三角函数math.h库详解

在C和C++中,math.h库提供了一系列用于处理数学运算的函数,包括三角函数、反三角函数等。以下是常用的三角函数、反三角函数和一些常用的其他函数,以及它们的简要介绍和示例,希望对你有所帮助。

ungu1314的博客 5077

c++ 三角函数_变化莫测的三角函数图像,你晕吗?

考纲原文(1)能画出y=sin x,y =cos x,y = tan x的图象,了解三角函数的周期性.(4)了解三角函数是描述周期变化现象的重要函数模型,会用三角函数解决一些简单实际问题。知识点详解一、正弦函数y=sinx,余弦函数y=cosx,正切函数y=tanx的图象与性质 考向分析考向一 三角函数的图象变换函数图象的平移变换解题策略(1)对函数y=sin x,y=Asin(ωx+φ)或y=A...

weixin_39875028的博客 512
上一篇: c++最大公因数和最小公倍数
下一篇: 高精度头文件
return_dr
博客等级 码龄5年 216粉丝 105原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值