Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI] Support gui.arrow() and gui.arrows() #1625

Merged
merged 1 commit into from
Aug 2, 2020

Conversation

archibate
Copy link
Collaborator

@archibate archibate commented Aug 1, 2020

Related issue = #

[Click here for the format server]


This could be useful when visualizing a vector field, particle velocities and forces.
It's completely based on gui.lines(), so no C++ changes involved. It's just handy for users so they don't have to hand-write that much numpy ad-hoc operations on their own.

To test:

import taichi as ti
import numpy as np

gui = ti.GUI()

orig = np.array([[0.5, 0.3], [0.3, 0.8]], dtype=np.float32)
dir = np.array([[-0.1, 0.4], [0.4, -0.2]], dtype=np.float32)

while gui.running and not gui.get_event(gui.ESCAPE):
    gui.arrows(orig, dir, radius=2, angle=25, tip_scale=0.4)
    #gui.arrow(orig[0], dir[0], radius=2)
    gui.show()

OFT: I assigned a default value title='Taichi' for ti.GUI since thinking about a title is often mind-taking, at least to me.

@codecov
Copy link

codecov bot commented Aug 1, 2020

Codecov Report

Merging #1625 into master will decrease coverage by 22.21%.
The diff coverage is 49.05%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1625       +/-   ##
===========================================
- Coverage   67.08%   44.87%   -22.22%     
===========================================
  Files          40       40               
  Lines        5691     5756       +65     
  Branches      993     1004       +11     
===========================================
- Hits         3818     2583     -1235     
- Misses       1699     3019     +1320     
+ Partials      174      154       -20     
Impacted Files Coverage Δ
python/taichi/__init__.py 0.00% <0.00%> (-75.00%) ⬇️
python/taichi/misc/__init__.py 0.00% <0.00%> (-100.00%) ⬇️
python/taichi/misc/gui.py 0.00% <0.00%> (-23.13%) ⬇️
python/taichi/misc/image.py 41.17% <0.00%> (-15.69%) ⬇️
python/taichi/misc/util.py 17.33% <0.00%> (-27.12%) ⬇️
python/taichi/lang/matrix.py 67.31% <33.33%> (-24.72%) ⬇️
python/taichi/testing.py 76.92% <76.92%> (ø)
python/taichi/lang/__init__.py 55.20% <100.00%> (-25.01%) ⬇️
python/taichi/lang/core.py 0.00% <0.00%> (-100.00%) ⬇️
python/taichi/core/__init__.py 0.00% <0.00%> (-100.00%) ⬇️
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6514e87...c79a2b4. Read the comment docs.

Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

angle = math.radians(180 - angle)
c, s = math.cos(angle), math.sin(angle)
minor1 = np.array([major[:, 0] * c - major[:, 1] * s,
major[:, 0] * s + major[:, 1] * c]).swapaxes(0, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this equivalent to transpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swapaxes? Yes!

@archibate archibate added the LGTM label Aug 2, 2020
@archibate archibate merged commit 4014f8f into taichi-dev:master Aug 2, 2020
@yuanming-hu yuanming-hu mentioned this pull request Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants