# [Tutor] Python & algorithms (Lang line simplification algorithm)

Laura Kauria lacation at gmail.com
Mon Apr 14 17:30:03 CEST 2014

```Thanks a lot for all the help! I got the courage to start at least..

I started by converting the pseudocode I had to python.

Still I have problems with perpendicular distance and creating a line with
python.
I need to create a line between two points and then check what is the
distance between a line and intermediate points which were between lines
start and end point. If someone could help me with this? I could not
understand can I do this without math library or not?

I'm a geographer student so all possible library suggestions concerning
spatial data is also appreciated.

Laura

2014-04-06 21:30 GMT+03:00 Danny Yoo <dyoo at hashcollision.org>:

> Hi Laura,
>
>
> Algorithmic code typically is simple enough that standard language
> features should suffice.  I think you might pick up an external
> library to make it easier to visualize graphical output, but the core
> algorithms there appear fairly straightforward.
>
> To get some familiarity with basic Python programming, take a look at
> a tutorial like:
>
>     http://www.greenteapress.com/thinkpython/thinkpython.html
>
> and see if you can pick up the basic language features of Python.  If
> you have questions with that tutorial, feel free to ask here.
>
>
> It looks like you need enough to work with structured data (classes)
> and the basic data structures (lists, numbers).  At least from my
> reading of the "curve simplification" page you pointed us to, I don't
> see anything there that's too bad.
>
> *  You'll want a way to represent points.  I think a structured value
> would be appropriate.  Think classes.
>
> *  You'll want to represent a sequence of these points.  In Java, you
> can hold that collection with ArrayLists or some other list
> implementation.  In Python, there's a generic list data structure that
> serves a similar purpose.
>
>
> For example, in Java, you'd represent structured data with classes,
> and a collection of these with a List<Person>:
>
> ///////////////////////////////////////////////////////////////
> class Person {
>     private String name;
>     public Person(String name) { this.name = name; }
>     public void greet() { System.out.println("Hello, my name is " + name);
> }
> }
>
> // Usage:
> Person p = new Person("Laura");
> p.sayHello();
> Person p2 = new Person("Lydia");
> List<Person> people = new ArrayList<>();
> ///////////////////////////////////////////////////////////////
>
>
> And in Python, you can do an analogous construction:
>
> #####################################
> class Person(object):
>     def __init__(self, name):
>         self.name = name
>     def greet(self):
>         print("Hello, my name is " + self.name)
>
> ## Usage
> p = Person("Laura")
> p.sayHello()
> p2 = Person("Lydia")
> people = []
> people.append(p)
> people.append(p2)
> #####################################
>
>
> So there should be a lot of transfer of basic knowledge between what
> you've learned in Java to Python programming.  Many of the concepts
> are the same, but the names are just different because of the Tower of
> Babel effect.  A basic tutorial of Python will cover these general
> topics.
>
>
> What might be domain-specific here is the visualization part: you'll
> want to make it easy to visually see the output of these graphical
> algorithms.  You may want to visualize these points on a graphical
> canvas on screen.  You could have your program generate an image file
> like a .png, .gif, or .svg file.
>
> Another approach may be to use a GUI toolkit that opens up a canvas as
> part of the program, where you can then manipulate the canvas.  If you
> want to take that approach, you might consider Tkinter, which is a GUI
> library that should come bundled with Python if I'm not mistaken.
> See:
>
>     http://effbot.org/tkinterbook/canvas.htm
>
> for a canvas example.  So once you have the basic algorithms down, you
> might use a Tkinter canvas to visualize and see that your algorithms
> are doing something reasonable.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140414/08ba9ceb/attachment.html>
```