-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Create vector3_for_2d_rendering.py #2496
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9590d36
Create vector3_for_2d_rendering.py
amaank404 57ee51c
Delete vector3_for_2d_rendering.py
amaank404 2775efe
Create vector3_for_2d_rendering.py
amaank404 d9fcc66
Update vector3_for_2d_rendering.py
amaank404 ae70f41
Update vector3_for_2d_rendering.py
amaank404 3e52831
Update vector3_for_2d_rendering.py
amaank404 ccb6c9f
Update vector3_for_2d_rendering.py
amaank404 828f11a
Update vector3_for_2d_rendering.py
amaank404 9975733
Update graphics/vector3_for_2d_rendering.py
amaank404 022f7d5
Update graphics/vector3_for_2d_rendering.py
amaank404 7b13ddc
Update graphics/vector3_for_2d_rendering.py
amaank404 af6cd9e
Update vector3_for_2d_rendering.py
amaank404 1bad0cc
Update vector3_for_2d_rendering.py
amaank404 a098a17
Update graphics/vector3_for_2d_rendering.py
amaank404 b2fee5d
Update graphics/vector3_for_2d_rendering.py
amaank404 fe96c7f
Apply suggestions from code review
amaank404 ff55531
Update vector3_for_2d_rendering.py
amaank404 c5f6164
Update vector3_for_2d_rendering.py
amaank404 f5e9d4e
Update vector3_for_2d_rendering.py
amaank404 44404ef
Update graphics/vector3_for_2d_rendering.py
amaank404 c5f35b5
Remove second main()
cclauss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
render 3d points for 2d surfaces. | ||
""" | ||
|
||
import math | ||
|
||
__version__ = "2020.9.26" | ||
__author__ = "xcodz-dot" | ||
|
||
|
||
def convert_to_2d(x: float, y: float, z: float, scale: float, | ||
distance: float) -> (float, float): | ||
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Converts 3d point to a 2d drawable point | ||
|
||
>>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) | ||
(7.6923076923076925, 15.384615384615385) | ||
""" | ||
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not isinstance(x, (float, int)): | ||
raise ValueError("x must be float or int") | ||
if not isinstance(y, (float, int)): | ||
raise ValueError("y must be float or int") | ||
if not isinstance(z, (float, int)): | ||
raise ValueError("z must be float or int") | ||
if not isinstance(scale, (float, int)): | ||
raise ValueError("scale must be float or int") | ||
if not isinstance(distance, (float, int)): | ||
raise ValueError("distance must be float") | ||
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
projected_x = ((x * distance) / (z + distance)) * scale | ||
projected_y = ((y * distance) / (z + distance)) * scale | ||
return projected_x, projected_y | ||
|
||
|
||
def rotate(x: float, y: float, z: float, axis: str, | ||
angle: float) -> (float, float, float): | ||
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
rotate a point around a certain axis with a certain angle | ||
angle can be any integer between 1, 360 and axis can be any one of | ||
'x', 'y', 'z' | ||
|
||
>>> rotate(1.0, 2.0, 3.0, 'y', 90.0) | ||
(3.130524675073759, 2.0, 0.4470070007889556) | ||
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
if not isinstance(angle, (int, float)): | ||
raise ValueError("Angel must be int or float") | ||
if angle > 360 or angle < 0: | ||
raise ValueError("Angle is supposed to be in between 0, 360") | ||
if not isinstance(x, (int, float)): | ||
raise ValueError("x must be int or float") | ||
if not isinstance(y, (int, float)): | ||
raise ValueError("y must be int or float") | ||
if not isinstance(z, (int, float)): | ||
raise ValueError("z must be int or float") | ||
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
angle = angle / 450 * 180 / math.pi | ||
if axis == 'z': | ||
new_x = x * math.cos(angle) - y * math.sin(angle) | ||
new_y = y * math.cos(angle) + x * math.sin(angle) | ||
new_z = z | ||
elif axis == 'x': | ||
new_y = y * math.cos(angle) - z * math.sin(angle) | ||
new_z = z * math.cos(angle) + y * math.sin(angle) | ||
new_x = x | ||
elif axis == 'y': | ||
new_x = x * math.cos(angle) - z * math.sin(angle) | ||
new_z = z * math.cos(angle) + x * math.sin(angle) | ||
new_y = y | ||
else: | ||
raise ValueError("not a valid axis, choose one of 'x', 'y', 'z'") | ||
|
||
return new_x, new_y, new_z | ||
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
amaank404 marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.