{ "info": { "author": "Fabricio J.C. Montenegro", "author_email": "fabriciojcmontenegro@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering :: Mathematics" ], "description": "# point2d\n\nThe `point2d` module contains only on class: `Point2D`.\n\nThis class describes Cartesian and polar coordinates for 2D points. It simultaneously represents the behavior of points (vectors) in a 2D space with Cartesian and polar coordinates, so that those can be used interchangeably. Changing one coordinate will change the value of the other, i.e., when changing a Cartesian coordinate, the polar coordinates will be recalculated, and vice-versa.\n\nNo methods need to be called to recalculate any of the coordinates, this is done automatically, e.g., if you set a new `x`, `r` and `a` will be updated.\n\n## Instalation\n\nFrom this folder run `python setup.py install`.\n\n## Usage\n\nYou can `import point2d` and use the class via `point2d.Point2D` or `from point2d import Point2D` and use `Point2D` directly from your code.\n\n### Attributes\n\nThe `Point2D` class has Cartesian coordinates represented by `x` and `y`, and polar coordinates (radius and angle) represented by `r` and `a`. If you change the value of `x` or `y`, `r` and `a` will be updated automatically, and vice-versa.\n\n### Creating a Point2D\n\nThere are five ways of creating a Point2D:\n\n1. Without any arguments. This will initialize it as the point (0, 0).\n```python\n>>> Point2D()\nPoint2D(0.0, 0.0)(0.0, 0.0)\n```\n2. With `x` and `y` as separate arguments.\n```python\n>>> Point2D(-1.0, 0.0)\nPoint2D(-1.0, 0.0)(1.0, 3.141592653589793)\n```\n3. With `x` and `y` as a single tuple.\n```python\n>>> Point2D((-1.0, 0.0))\nPoint2D(-1.0, 0.0)(1.0, 3.141592653589793)\n```\n4. With `r` and `a` as separate arguments.\n```python\n>>> Point2D(r=1.0, a=math.pi)\nPoint2D(-1.0, 1.2246467991473532e-16)(1.0, 3.141592653589793)\n```\n5. Copying another Point2D:\n```python\n>>> Point2D(Point2D(-1.0, 0.0))\nPoint2D(-1.0, 0.0)(1.0, 3.141592653589793)\n```\n\n### Functionalities\n\nAs said earlier, the class automatically keeps track of cartesian and polar coordinates.\n\n```python\n>>> p = Point2D()\n>>> print(p) \nPoint2D(0.0, 0.0)(0.0, 0.0)\n>>> p.x = -1.0\n>>> print(p)\nPoint2D(-1.0, 0.0)(1.0, 3.141592653589793)\n>>> p.r = 5.0\n>>> print(p)\nPoint2D(-5.0, 6.123233995736766e-16)(5.0, 3.141592653589793)\n```\n\nThe class also implements operation between points (they return a new Point2D).\n```python\n>>> p1 = Point2D(10.0, 0.0)\n>>> p2 = Point2D(0.0, 10.0)\n>>> p1 + p2\nPoint2D(10.0, 10.0)(14.142135623730951, 0.7853981633974483)\n>>> p1 - p2\nPoint2D(10.0, -10.0)(14.142135623730951, -0.7853981633974483)\n```\nYou can update a point through a sum or subtraction between points if you do it like this:\n```python\n>>> p1 += p2\n>>> p1\nPoint2D(10.0, 10.0)(14.142135623730951, 0.7853981633974483)\n>>> p1 -= p2\n>>> p1\nPoint2D(10.0, 0.0)(10.0, 0.0)\n```\nThe class also implements operation between points and scalars.\n```python\n>>> Point2D(1.0, 0.0) * 10\nPoint2D(10.0, 0.0)(10.0, 0.0)\n```\n\n### Getting and setting\n\nYou can get and set values to the coordinates directly through their names (`x`, `y`, `r`, `a`), but there are some useful methods to help you on the way.\n\n#### Cartesian Coordinates\n\nThe `cartesian()` method can set Cartesian coordinates or return them. You can set them with `x` and `y` as separate arguments, with a tuple containing `x`and `y`, or use this method to get a tuple containing `x` and `y`.\n```python\n>>> p = Point2D()\n>>> p.cartesian(1.0, 0.0)\n>>> p\nPoint2D(0.0, 0.0)(0.0, 0.0)\n>>> p.cartesian((-1.0, 0.0))\n>>> p\nPoint2D(-1.0, 0.0)(1.0, 3.141592653589793)\n>>> p.cartesian()\n(-1.0, 0.0)\n```\nYou can also use the method `ints()` to get a tuple of ints with the cartesian coordinates. This is especially useful if you're working with Pygame.\n\n#### Polar Coordinates\n\nThe `polar()` method does the same thing for polar coordinates. You can set them with `r` and `a` as separate arguments, with a tuple containing `r`and `a`, or use this method to get a tuple containing `r` and `a`.\n```python\n>>> p = Point2D()\n>>> p.polar(1.0, 0.0)\n>>> p\nPoint2D(1.0, 0.0)(1.0, 0.0)\n>>> p.polar((1.0, math.pi))\n>>> p\nPoint2D(-1.0, 1.2246467991473532e-16)(1.0, 3.141592653589793)\n>>> p.polar()\n(1.0, 3.141592653589793)\n```\n### Useful Tricks\n\nYou can work solely with Cartesian coordinates with this class and it's still useful. Here are some nice \"tricks\".\n\n#### Length of a vector\n\nRemember that the radius of a point, in polar coordinates, is its distance to the origin, which is the same as the length of a vector located at the origin.\n\nUse `mypoint.r` to find out its length.\n```python\n>>> p = Point2D(3, 4)\n>>> p.r\n5.0\n```\n\n#### Distance between points\n\nSubtracting two points will give you a third point. The length of this third point is the distance between the two first points. Use its radius to get the length.\n```python\n>>> p1 = Point2D(10, 0)\n>>> p2 = Point2D(10, 10)\n>>> (p2 - p1).r\n10.0\n```\n\n#### Angle between vectors\n\nAgain, subtracting two vectors will give you a third. The angle of this third vector is the angle between the two first vectors. Be careful, though, `p1 - p2` is not the same as `p2 - p1`. Although they will yield supplementary angles (their sum is 180\u00b0).\n```python\n>>> p1 = Point2D(10, 0)\n>>> p2 = Point2D(10, 10)\n>>> math.degrees((p2 - p1).a)\n90.0\n>>> math.degrees((p1 - p2).a)\n-90.0\n```\n\n#### Scaling vectors\n\nThere are two ways to do this. One of them is to multiply the vector by the number that describes its scaling factor. The other way is multiplying its radius by the number.\n```python\n>>> p = Point2D(1,0)\n>>> p *= 3\n>>> p\nPoint2D(3.0, 0.0)(3.0, 0.0)\n>>> p = Point2D(1,0)\n>>> p.r *= 3\n>>> p\nPoint2D(3.0, 0.0)(3.0, 0.0)\n```\n\n#### Unit vector\n\nThe unit vector is a vector of magnitude 1. To find the unit vector of a vector, you need to multiply the vector by its length, which can be kind of annoying. Well, it's easy now. Just set its radius to 1 and it's done. You're welcome.\n\n```python\n>>> p = Point2D(12.34, 56.78)\n>>> p.r = 1\n>>> p\nPoint2D(0.21237248410903914, 0.9771887883072318)(1.0, 1.3567941381565736)\n```\n\n## Links\n\n\nCode: [https://github.com/SplinterDev/point2d/](https://github.com/SplinterDev/point2d/)\n\nLicense: [GNU General Public License v3.0](https://github.com/SplinterDev/point2d/blob/master/LICENSE)\n\nCreated By: [Fabr\u00edcio J.C. Montenegro](https://github.com/SplinterDev) (2018)\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/SplinterDev/point2d", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "point2d", "package_url": "https://pypi.org/project/point2d/", "platform": "", "project_url": "https://pypi.org/project/point2d/", "project_urls": { "Homepage": "https://github.com/SplinterDev/point2d" }, "release_url": "https://pypi.org/project/point2d/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "2D point class to represent cartesian and polar coordinates seemlessly.", "version": "0.0.1" }, "last_serial": 4572907, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "6e467f6a35b45463e4a8c12b816baa83", "sha256": "192a5a1b1f5c628b08577574f8949ac18cbad7b647c1b5f0135e2071377f58f6" }, "downloads": -1, "filename": "point2d-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "6e467f6a35b45463e4a8c12b816baa83", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17739, "upload_time": "2018-12-07T18:26:44", "url": "https://files.pythonhosted.org/packages/38/6d/4f55fc1fe656a90d360114e3ed72aff59166034c436e8512163dfb44fa42/point2d-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "af8c6632f458fe9f26bdaaecf3b85bfc", "sha256": "1c3a64b2dc3200e7a40eff846ebe76c5fb7dd8bc1f80a1e524cc7a9fdebc4997" }, "downloads": -1, "filename": "point2d-0.0.1.tar.gz", "has_sig": false, "md5_digest": "af8c6632f458fe9f26bdaaecf3b85bfc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5302, "upload_time": "2018-12-07T18:26:46", "url": "https://files.pythonhosted.org/packages/dc/80/b92cdaa3f0325214a9b45f5abda0b08740d38b1b2912bfbd45184bc4bdd4/point2d-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6e467f6a35b45463e4a8c12b816baa83", "sha256": "192a5a1b1f5c628b08577574f8949ac18cbad7b647c1b5f0135e2071377f58f6" }, "downloads": -1, "filename": "point2d-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "6e467f6a35b45463e4a8c12b816baa83", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17739, "upload_time": "2018-12-07T18:26:44", "url": "https://files.pythonhosted.org/packages/38/6d/4f55fc1fe656a90d360114e3ed72aff59166034c436e8512163dfb44fa42/point2d-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "af8c6632f458fe9f26bdaaecf3b85bfc", "sha256": "1c3a64b2dc3200e7a40eff846ebe76c5fb7dd8bc1f80a1e524cc7a9fdebc4997" }, "downloads": -1, "filename": "point2d-0.0.1.tar.gz", "has_sig": false, "md5_digest": "af8c6632f458fe9f26bdaaecf3b85bfc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5302, "upload_time": "2018-12-07T18:26:46", "url": "https://files.pythonhosted.org/packages/dc/80/b92cdaa3f0325214a9b45f5abda0b08740d38b1b2912bfbd45184bc4bdd4/point2d-0.0.1.tar.gz" } ] }