Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
geekincode
Hyperbola
提交
13547ac4
Hyperbola
项目概览
geekincode
/
Hyperbola
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Hyperbola
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
13547ac4
编写于
10月 31, 2021
作者:
geekincode
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
上传新文件
上级
a4a9bc76
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
97 addition
and
0 deletion
+97
-0
Hyperbola_draw.py
Hyperbola_draw.py
+97
-0
未找到文件。
Hyperbola_draw.py
0 → 100644
浏览文件 @
13547ac4
class
hyperbola
():
def
__init__
(
self
,
ax_range
=
100
,
line_range
=
200
):
import
matplotlib.pyplot
as
plt
# self.a = a
# self.b = b
self
.
x
=
[]
self
.
y
=
[]
self
.
fig
,
self
.
ax
=
plt
.
subplots
()
self
.
plt
=
plt
self
.
ax_range
=
ax_range
self
.
line_range
=
line_range
# self.focus = focus
def
hb_data
(
self
,
a
,
b
,
focus
=
'x'
):
import
math
import
numpy
as
np
self
.
a
,
self
.
b
,
self
.
focus
=
a
,
b
,
focus
line_range
=
self
.
line_range
c
=
math
.
sqrt
(
a
**
2
+
b
**
2
)
foucs_1
=
[
-
c
,
0
]
foucs_2
=
[
c
,
0
]
x1
=
list
(
np
.
linspace
(
-
line_range
,
-
a
,
line_range
*
10
))
y
=
[]
for
x_
in
x1
:
dot
=
math
.
sqrt
(
abs
((
b
*
x_
/
a
)
**
2
-
b
**
2
))
y
.
append
(
dot
)
y
.
append
(
-
dot
)
x1
=
x1
+
x1
[::
-
1
]
y
.
sort
(
reverse
=
True
)
x2
=
list
(
np
.
linspace
(
a
,
line_range
,
line_range
*
10
))
x2
=
x2
[::
-
1
]
+
x2
return
x1
,
y
,
x2
def
hb_draw
(
self
,
data
):
ax
=
self
.
ax
if
self
.
focus
==
'x'
:
ax
.
plot
(
data
[
0
],
data
[
1
],
color
=
'lightcoral'
,
label
=
'hyperbola'
)
ax
.
plot
(
data
[
2
],
data
[
1
],
color
=
'lightcoral'
)
elif
self
.
focus
==
'y'
:
ax
.
plot
(
data
[
1
],
data
[
0
],
color
=
'lightcoral'
,
label
=
'hyperbola'
)
ax
.
plot
(
data
[
1
],
data
[
2
],
color
=
'lightcoral'
)
else
:
print
(
'You maked an error on focus!!!'
)
self
.
decorate
()
def
decorate
(
self
):
ax
,
ax_range
=
self
.
ax
,
self
.
ax_range
ax
.
spines
[
'top'
].
set_visible
(
False
)
#顶边界不可见
ax
.
xaxis
.
set_ticks_position
(
'bottom'
)
# ticks 的位置为下方,分上下的。
ax
.
spines
[
'right'
].
set_visible
(
False
)
#右边界不可见
ax
.
yaxis
.
set_ticks_position
(
'left'
)
# 移动边界,按 Axes 的百分比位置
ax
.
spines
[
'bottom'
].
set_position
((
'axes'
,
0.5
))
ax
.
spines
[
'left'
].
set_position
((
'axes'
,
0.5
))
ax
.
set
(
title
=
'Draw Hyperbola'
,
xlim
=
[
-
ax_range
,
ax_range
],
ylim
=
[
-
ax_range
,
ax_range
])
ax
.
legend
()
def
asymptote
(
self
):
import
numpy
as
np
line_range
,
focus
=
self
.
line_range
,
self
.
focus
x
=
list
(
np
.
linspace
(
-
line_range
,
line_range
,
10
))
#渐近线
y
=
[(
self
.
b
/
self
.
a
)
*
x_
for
x_
in
x
]
if
self
.
focus
==
'x'
:
self
.
ax
.
plot
(
x
,
y
,
color
=
'skyblue'
)
self
.
ax
.
plot
(
x
[::
-
1
],
y
,
color
=
'skyblue'
)
elif
self
.
focus
==
'y'
:
self
.
ax
.
plot
(
y
,
x
,
color
=
'skyblue'
)
self
.
ax
.
plot
(
y
,
x
[::
-
1
],
color
=
'skyblue'
)
def
display
(
self
):
self
.
plt
.
show
()
if
__name__
==
'__main__'
:
h
=
hyperbola
(
30
,
100
)
d1
=
h
.
hb_data
(
10
,
13
,
focus
=
'x'
)
h
.
hb_draw
(
d1
)
h
.
asymptote
()
d2
=
h
.
hb_data
(
10
,
13
,
focus
=
'y'
)
h
.
hb_draw
(
d2
)
h
.
asymptote
()
h
.
display
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录