技术博客
科学计算器三角函数角度制实战:rad 弧度 vs ang 角度怎么选?

科学计算器三角函数角度制实战:rad 弧度 vs ang 角度怎么选?

作者: 万维易源
2026-09-03
科学计算器三角函数角度制
# 科学计算器三角函数角度制实战:rad 弧度 vs ang 角度怎么选? > 接口 免费科学计算器(apiCode 1699)· 接入点 科学计算器(1699-1)· 免费 · POST/GET · 返回 JSON · 适合 学生 / 教师 / 开发者 · 阅读约 4 分钟 ## 核心要点 - 三角函数(`sin`/`cos`/`tan` 及其反函数、双曲函数)通过 `rad_or_ang` 参数区分单位。 - 传 `ang` = 角度制(如 `sin(30°)`),不传或传 `rad` = 弧度制(默认)。 - **反三角函数(arcsin / arccos 等)一律返回弧度**,调用时注意单位换算。 ## Why:为什么角度是高频坑 大多数人和教材用的是「度」(30°、60°、90°),而计算器默认按「弧度」算。直接传 `num=30&operation=sin` 不传角度制,算的是 `sin(30 弧度)≈-0.988`,和预期的 `0.5` 差很远——这会让人以为接口算错了,其实只是没声明单位。 ## What:接口速览 | 项目 | 说明 | |------|------| | 请求地址 | `https://route.showapi.com/1699-1?appKey={your_appKey}` | | 角度参数 | `rad_or_ang`:`ang`(角度)/ `rad`(弧度,可留空) | | 计费 | 免费,[使用档次限制](https://www.showapi.com/free-api) | 支持的三角函数操作名:`sin` `cos` `tan` `cot` `sec` `csc` 及其反函数 `arcsin` `arccos` `arctan` `arccot` `arcsec` `arccsc`,以及双曲族 `sinh` `cosh` `tanh` `coth` `sech` `csch`。 ## How:角度制正确写法 ### 角度制(ang) ```python import requests APP_KEY = "YOUR_APPKEY" def trig(num, op, unit="ang"): r = requests.post( "https://route.showapi.com/1699-1", params={"appKey": APP_KEY}, data={"num": num, "operation": op, "rad_or_ang": unit}, timeout=10 ) b = r.json()["showapi_res_body"] return b["result"] if str(b.get("ret_code")) == "0" else f"失败: {b.get('remark')}" print(trig("30", "sin")) # 0.5 (sin30°) print(trig("60", "cos")) # 0.5 (cos60°) print(trig("45", "tan")) # 1.0 (tan45°) ``` ### cURL ```bash curl -X POST "https://route.showapi.com/1699-1?appKey=YOUR_APPKEY" \ -H "content-type: application/x-www-form-urlencoded" \ -d "num=30&operation=sin&rad_or_ang=ang" ``` ### Node.js ```javascript const APP_KEY = "YOUR_APPKEY"; const body = new URLSearchParams({ num: "30", operation: "sin", rad_or_ang: "ang" }); fetch(`https://route.showapi.com/1699-1?appKey=${APP_KEY}`, { method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body }).then(r => r.json()).then(res => { const b = res.showapi_res_body; console.log(String(b.ret_code) === "0" ? b.result : b.remark); }); ``` ## 返回示例与解析 请求 `num=30&operation=sin&rad_or_ang=ang` 真实返回(实测): ```json { "showapi_res_code": 0, "showapi_res_body": { "ret_code": 0, "remark": "成功", "result": 0.5 } } ``` | 调用 | 结果 | 说明 | |------|------|------| | `sin` 30, ang | `0.5` | sin30° | | `cos` 60, ang | `0.5` | cos60° | | `tan` 45, ang | `1.0` | tan45° | | `arccos` 0, rad | `1.5708` | 反余弦返回弧度(π/2) | | `sin` 30(不传单位) | `-0.988…` | 按弧度算 sin(30),非预期 | > 注意浮点尾差:`sin(30,ang)` 实测为 `0.49999999999999994`,展示时建议四舍五入。 ## 进阶 / 边界 - **反三角返回弧度**:`arccos(0)=1.5708`(即 π/2 弧度),不是 90 度。要显示角度需自行 `×180/π`。 - **双曲函数同理**:`sinh`/`cosh` 等也受 `rad_or_ang` 影响,但通常双曲函数用弧度。 - **弧度 ↔ 角度**:角度 = 弧度 × 180 / π;弧度 = 角度 × π / 180。 ## FAQ **Q1:不传 `rad_or_ang` 默认是什么单位?** 默认弧度(等同传 `rad`)。 **Q2:为什么我算 `sin(30)` 得到 -0.988?** 因为没声明角度制,接口把 30 当成 30 弧度。加上 `rad_or_ang=ang` 即得 `0.5`。 **Q3:反三角函数返回的是角度还是弧度?** 返回弧度。如 `arcsin(1)=1.5708` 弧度(=90°)。 **Q4:能直接算 `sin(30°)` 这种带符号的输入吗?** `num` 只接受数字,角度制通过 `rad_or_ang=ang` 声明,不要把 `°` 写进 `num`。 **Q5:浮点结果有误差怎么办?** 属正常现象(如 0.49999…),前端展示时按所需精度 `toFixed` 即可。 ## 相关能力 / 下一步阅读 - [科学计算器操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699) —— 全部三角/双曲操作名 - [科学计算器幂与根用法](https://www.showapi.com/guides/calculator-power-root-1699) —— `square` / `sqrt` 多参数 - [科学计算器对数体系](https://www.showapi.com/guides/calculator-log-ln-1699) —— `log` 与 `ln` 区别 - **本系列共 11 篇**:查看[科学计算器开发指南总目录](https://www.showapi.com/guides/calculator-guides-1699)