Return the angle of the line from the turtle's position to (x, y). Arguments: x -- a number or a pair/vector of numbers or a turtle instance y -- a number None None call: distance(x, y) # two coordinates
(self, x, y=None)
| 1859 | return abs(pos - self._position) |
| 1860 | |
| 1861 | def towards(self, x, y=None): |
| 1862 | """Return the angle of the line from the turtle's position to (x, y). |
| 1863 | |
| 1864 | Arguments: |
| 1865 | x -- a number or a pair/vector of numbers or a turtle instance |
| 1866 | y -- a number None None |
| 1867 | |
| 1868 | call: distance(x, y) # two coordinates |
| 1869 | --or: distance((x, y)) # a pair (tuple) of coordinates |
| 1870 | --or: distance(vec) # e.g. as returned by pos() |
| 1871 | --or: distance(mypen) # where mypen is another turtle |
| 1872 | |
| 1873 | Return the angle, between the line from turtle-position to position |
| 1874 | specified by x, y and the turtle's start orientation. (Depends on |
| 1875 | modes - "standard" or "logo") |
| 1876 | |
| 1877 | Example (for a Turtle instance named turtle): |
| 1878 | >>> turtle.pos() |
| 1879 | (10.00, 10.00) |
| 1880 | >>> turtle.towards(0,0) |
| 1881 | 225.0 |
| 1882 | """ |
| 1883 | if y is not None: |
| 1884 | pos = Vec2D(x, y) |
| 1885 | if isinstance(x, Vec2D): |
| 1886 | pos = x |
| 1887 | elif isinstance(x, tuple): |
| 1888 | pos = Vec2D(*x) |
| 1889 | elif isinstance(x, TNavigator): |
| 1890 | pos = x._position |
| 1891 | x, y = pos - self._position |
| 1892 | result = round(math.degrees(math.atan2(y, x)), 10) % 360.0 |
| 1893 | result /= self._degreesPerAU |
| 1894 | return (self._angleOffset + self._angleOrient*result) % self._fullcircle |
| 1895 | |
| 1896 | def heading(self): |
| 1897 | """ Return the turtle's current heading. |