-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams.json
More file actions
1 lines (1 loc) · 7.22 KB
/
Copy pathparams.json
File metadata and controls
1 lines (1 loc) · 7.22 KB
1
{"name":"V3d","tagline":"v3d (Stands for Vector 3D) is a 3D vector library for basic Vector operations.","body":"<img width=128 src=\"https://repository-images.githubusercontent.com/279284161/03424980-cb66-11ea-8696-004da6e8b5c5\" alt=\"V3d\"/>\r\n\r\n# v3d\r\nv3d (Stands for Vector 3D) is a 3D vector library for basic Vector operations.\r\nIt was inspired by: https://github.com/allelos/vectors\r\n\r\n## WHY?\r\nA library was created by https://github.com/allelos/. However there was some missing parts(such as from_mag_and_dir).\r\n\r\n## Installation\r\n\r\n```bash\r\npip install v3d\r\n```\r\n## Documentation\r\n### Concept\r\nThis work inspired by https://github.com/allelos/vectors\r\n\r\nV3D has no dependency other than standard math and logging module.\r\n\r\nIt consists of two parts, Point and Vector.\r\n\r\nA point is a class with multiple operations. It is also a data carrier for Vector.\r\n\r\nOperations:\r\n- to_polar -> Converts from cartesian to polar\r\n- from_polar -> Converts polar to cartesian\r\n- add -> Calculates addition of two points\r\n- subtract -> Calculates subtraction of two points. Uses add\r\n- scale -> Calculates multiplication a point with a scalar\r\n- divide -> Calculates division a point with a scalar. Uses scale\r\n- dist -> Calculates distance between two points or a point and origin\r\n- is_same -> Checks if two points are same\r\n\r\nVector is a module with multiple operations.\r\n\r\nOperations:\r\n- from_points -> Creates a Vector from two points\r\n- add -> Calculates addition of two vectors. Uses Point.add\r\n- subtract -> Calculates subtraction of two vectors. Uses add\r\n- multiply -> Calculates cross product of two vectors or scales a vector with a scalar\r\n- divide -> Scales a vector with 1/scalar. Uses multiply\r\n- dot -> Calculates dot product of two vectors\r\n- rotate -> Calculates a retated vector around given alpha, beta, gamma (alpha in x, beta in y and gamma in z axis)\r\n- mag -> Calculates magnitude of a vector\r\n- unit -> Calculates unit vector of a vector\r\n- normal -> Calculates normal vector of a vector\r\n- heading -> Calculates heading direction of a vector\r\n- angle_between -> Calculates angle between two vectors\r\n- is_parallel -> Checks if two vectors are parallel\r\n- is_perpendicular -> Checks if two vectors are perpendicular\r\n- is_non_parallel -> Checks if two vectors are neither parallel nor perpendicular\r\n- is_same -> Checks if two vectors are same\r\n\r\n### Point\r\nCreating a Point:\r\n```python3\r\nfrom v3d import Vector, Point\r\n\r\np1 = Point()# This will create a zero point. (0, 0, 0)\r\np2 = Point(1, 3, 1)# This will create a point at (1, 3, 1)\r\n```\r\nConverting between Polar and Cartesian:\r\n```python3\r\np2.to_polar()# r, theta, phi (angles are in degrees)\r\n# (3.3166247903554, 72.4515993862077, 71.56505117707799)\r\np1.from_polar(1, 45, 0)# Overrides p1 with new x, y and z. Set override to False to get a return\r\n```\r\nAdd/Subtract:\r\n```python3\r\n# Add\r\np1.add(p2)\r\n# Point(x=1.7071067811865475, y=3.0, z=1.7071067811865475)\r\np2.add(p1)\r\n# Point(x=1.7071067811865475, y=3.0, z=1.7071067811865475)\r\np1 + p2\r\n# Point(x=1.7071067811865475, y=3.0, z=1.7071067811865475)\r\np2 + p1\r\n# Point(x=1.7071067811865475, y=3.0, z=1.7071067811865475)\r\n\r\n# Subtract\r\np1.subtract(p2)\r\n# Point(x=-0.29289321881345254, y=-3.0, z=-0.2928932188134524)\r\np1 - p2\r\n# Point(x=-0.29289321881345254, y=-3.0, z=-0.2928932188134524)\r\n\r\np2.subtract(p1)\r\n# Point(x=0.29289321881345254, y=3.0, z=0.2928932188134524)\r\np2 - p1\r\n# Point(x=0.29289321881345254, y=3.0, z=0.2928932188134524)\r\n```\r\nMultiply/Divide\r\n```python3\r\np2.scale(2)\r\n# Point(x=2, y=6, z=2)\r\np2 * 2\r\n# Point(x=2, y=6, z=2)\r\n\r\np2.divide(2)\r\n# Point(x=0.5, y=1.5, z=0.5)\r\np2 / 2\r\n# Point(x=0.5, y=1.5, z=0.5)\r\n```\r\nOther Operations:\r\n\r\n```python3\r\n# Distance from origin:\r\np1.dist()\r\n# 1.0\r\n\r\n# Distance from other point:\r\np1.dist(p2)\r\n# 3.028460479394408\r\n\r\n# Check if two point are the same:\r\np1.is_same(p2)\r\n# False\r\np1 == p2\r\n# False\r\n\r\n# Notice we made a copy of p2 as p3\r\np3 = p2.copy()\r\n\r\np2.is_same(p3)\r\n# True\r\np2 == p3\r\n# True\r\n```\r\n### Vector\r\nCreating a Vector:\r\n```python3\r\n# Notice p1 is a point type. It was created before.\r\nv1 = Vector(p1)\r\n# Vector(Point(x=0.7071067811865475, y=0.0, z=0.7071067811865476))\r\n```\r\n\r\nMagnitude, heading and unit vector:\r\n```python3\r\nv1.mag()\r\n# 1.0\r\nabs(v1)\r\n# 1.0\r\n\r\nv1.heading()\r\n# (45.0, 0.0)\r\n\r\nv1.unit()\r\n# Vector(Point(x=0.7071067811865475, y=0.0, z=0.7071067811865476))\r\n```\r\nRotate:\r\n```python3\r\nv1.rotate(alpha=45, beta=0, gamma=0)# alpha in x, beta in y and gamma in y axis\r\n# Vector(Point(x=0.7071067811865475, y=-0.5, z=0.5000000000000001))\r\n```\r\nAdd/Subtract:\r\n```python3\r\n# Creating a new vector from p2\r\nv2 = Vector(p2)\r\n\r\nv1.add(v2)\r\n# Vector(Point(x=1.7071067811865475, y=3.0, z=1.7071067811865475))\r\nv1 + v2\r\n# Vector(Point(x=1.7071067811865475, y=3.0, z=1.7071067811865475))\r\n\r\nv1.subtract(v2)\r\n# Vector(Point(x=-0.29289321881345254, y=-3.0, z=-0.2928932188134524))\r\nv1 - v2\r\n# Vector(Point(x=-0.29289321881345254, y=-3.0, z=-0.2928932188134524))\r\n```\r\nMultiply:\r\n```python3\r\nv1.multiply(2)\r\n# Vector(Point(x=1.414213562373095, y=0.0, z=1.4142135623730951))\r\nv1 * 2\r\n# Vector(Point(x=1.414213562373095, y=0.0, z=1.4142135623730951))\r\n\r\n# In case of two vector multiplication cross product will be calculated.\r\nv1.multiply(v2)\r\n# Vector(Point(x=-2.121320343559643, y=1.1102230246251565e-16, z=2.1213203435596424))\r\nv1 * v2\r\n# Vector(Point(x=-2.121320343559643, y=1.1102230246251565e-16, z=2.1213203435596424))\r\n\r\nv1.divide(2)\r\n# Vector(Point(x=0.35355339059327373, y=0.0, z=0.3535533905932738))\r\nv1 / 2\r\n# Vector(Point(x=0.35355339059327373, y=0.0, z=0.3535533905932738))\r\n\r\n# These two lines will raise an error. Vector by Vector division is not possible\r\nv1.divide(v2)\r\nv1 / v2\r\n```\r\n\r\nDot product:\r\n```python3\r\nv1.dot(v2)\r\n# 1.414213562373095\r\n```\r\nOther operations:\r\n```python3\r\n# Angle between two vectors\r\nv1.angle_between(v2)\r\n# 64.7605981793211\r\n\r\n# Check if two vector are same\r\nv1.is_same(v2)\r\n# False\r\nv1 == v2\r\n# False\r\n\r\n# Noice Points p2 and p3 are the same so will the vectors be\r\nv3 = Vector(p3)\r\nv2.is_same(v3)\r\n# True\r\nv2 == v3\r\n# True\r\n\r\n\r\n# Check if two vectors are perpendicular\r\n# We know cross product of two vectors will be a vector perpendicular to other two vectors\r\n\r\ncross_product = v1 * v2\r\ncross_product.is_perpendicular(v1) and cross_product.is_perpendicular(v2)\r\n# True\r\n\r\n# Check if two vectors are parallel\r\n# We know cross product of two vectors will be a vector perpendicular to other two vectors\r\n\r\ncross_product.is_parallel(v1) or cross_product.is_parallel(v2)\r\n# False\r\n\r\n# Check if two vectors are non_parallel\r\n# We know cross product of two vectors will be a vector perpendicular to other two vectors\r\n\r\ncross_product.is_non_parallel(v1) and cross_product.is_non_parallel(v2)\r\n# True\r\n\r\n```\r\n\r\n## Example\r\n\r\nExample: https://github.com/mshemuni/V3D/blob/master/example.ipynb\r\n","note":"Don't delete this file! It's used internally to help with page regeneration."}