Re: [Tutor] Python algorithms (Lang line simplification algorithm)

2014-04-15 Thread Laura Kauria
Okay I'll try. What the main job is to do an algorithm which simples a
line. Algorithm deletes points which are unnecessary accurate according to
tolerance distance user gives.

 I started by converting the pseudocode I had to python.

Pseudocode:
http://web.cs.sunyit.edu/~poissad/projects/Curve/about_algorithms/lang


   1. function lang(PointList[], Tolerance)
   2. key=0
   3. endP= PointList.length-1
   4. do {
   5. endP= PointList.length-1
   6. if (key+1 != endP) // If there are intermediate points
   7. line= new Line( PointList[key], PointList[endP])
   8. /* Find the point with the furthest perpendicular distance */
   9. maxIndex= key+1
   10. maxD= perpendicularDistance(line, PointList[maxIndex])
   11. for (i=maxIndex+1; iendP; i++)
   12. d= perpendicularDistance(line, PointList[i])
   13. if (d  maxD)
   14. maxIndex=i
   15. maxD=d
   16. if (maxD  Tolerance)
   17. endP--;
   18. else
   19. for (i=key+1; iendP; i++)
   20. PointList.remove(i)
   21. key= endP
   22. } while ( endP != PointList.length-1 )
   23. end


 Still I have problems with perpendicular distance and creating a line
 with python.

What I mean by creating a line is what Alan answered checking
distances/intersections
etc only requires the math model. I need the mathematical model not a
picture/graph. I'll try move forward with Bens suggestion of ‘math’ module
which probably help me with both mathematical line model between two points
and its distance between the intermediate points.
 URL:http://docs.python.org/3/library/math.html#trigonometric-functions.

Here is a picture of the lang algorithm, where you can see distance of
interest by purple
http://psimpl.sourceforge.net/lang.html.

I'll ask later if I can't get this work.

Cheers!





2014-04-15 3:23 GMT+03:00 Ben Finney ben+pyt...@benfinney.id.au:

 Laura Kauria lacat...@gmail.com writes:

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

 Congratulations! Courage is a necessary ingredient when starting :-)

 Could you please avoid  top-posting, and instead use interleaved style
 URL:https://en.wikipedia.org/wiki/Posting_style#Interleaved_style for
 your replies, so the conversation is in a natural order.

  I started by converting the pseudocode I had to python.

 If it's short and simple, please post it here so we can discuss it in
 context.

  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?

 The ‘math’ module in the standard library has trigonometric functions
 URL:http://docs.python.org/3/library/math.html#trigonometric-functions.
 If you have co-ordinate data and know how to use trigonometry, then
 those functions will do what you expect.

 --
  \“If I melt dry ice, can I swim without getting wet?” —Steven |
   `\Wright |
 _o__)  |
 Ben Finney

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python algorithms (Lang line simplification algorithm)

2014-04-14 Thread Laura Kauria
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 d...@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 ListPerson:

 ///
 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);
 ListPerson people = new ArrayList();
 people.add(p);
 people.add(p2);
 ///


 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.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python algorithms (Lang line simplification algorithm)

2014-04-14 Thread Laura Kauria
Hi,

sorry I don't know the conventions yet.

I'd need to know how to create a line between two points. I don't know
after many hours checking, how to convert this pseudocode to python.

line = new Line( pointList[startPoint], pointList[endPoint])

I've done point list and indexes already, put don't know how to create the
line.

Laura


2014-04-14 22:21 GMT+03:00 bob gailer bgai...@gmail.com:

 On 4/14/2014 11:30 AM, Laura Kauria wrote:

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

  Some requests regarding posts.

 1) put your comments following the relevant text rather than at the top.
 2) delete old (irrelevant) text.
 4) be more clear with your questions.

  I started by converting the pseudocode I had to python.


 3) post your code

  Still I have problems with perpendicular distance and creating a line
 with python.
 I need to create a line between two points

 what does that mean (apart from the obvious) in terms of your code

 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'm a geographer student so all possible library suggestions concerning
 spatial data is also appreciated.

  4) be more clear with your questions.

 I can make guesses about what you want, but that wastes time.

  distance between a line and intermediate points which were between lines
 start and end point as I read this the answer seems to be zero. ( a point
 that is between lines start and end point is on the line). I don't think
 you mean that.

 We are here to help. The more you tell us the easier it is for us to help.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python algorithms (Lang line simplification algorithm)

2014-04-06 Thread Laura Kauria
Hi all,

I'm new with python and have done little coding with Java. At uni I would
need to start a coding task with python writing a proper/working code and
we don't get much help at school.

Can someone help with which kinds of libraries I need to download to start
to work with lists consisting coordinates?

Here are a pseudocode of the algorithm
http://web.cs.sunyit.edu/~poissad/projects/Curve/about_algorithms/lang


Thanks for all the answers!


Laura
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor