Grasshopper

algorithmic modeling for Rhino

Hi all,

 I would like from a line find precise coordinates in X and Y to implement this line.

Exemple: this line:

I looking a coordinate round in the "infinte" line:

In this example I cheated by first tracing the line with precise coordinates, but the goal would be to start from a Line Draws without coorodnées.

Thanks for all !

Views: 1049

Replies to This Discussion

Hello Remy,

If your lines are random, mathematically, I don't think this is possible.

Your line has a y=Ax+B equation.

If it is a random line, A and B will also be random numbers, which means you won't have silmutaneously x and y coordinates as integers unless you're really lucky.

The best you can do to have round coordinates is to find the closest line with round A and B parameters.

If it is a random line, A and B will also be random numbers, which means you won't have silmutaneously x and y coordinates as integers unless you're really lucky.

Yes I would like to play with that chance ...

Maybe with galapagos or VB script ...

I guess you could use galapagos to find points on the line with a round x coordinate and a y coordinate as close as possible to a round number (like 13.0000054).

With a high level of precision, you'll get the best approximated line.

For nikos : I tried the grid approach... but it can be a lot of points!!!

My level of precision it's 0.0001 !

For nikos : I tried the grid approach... but it can be a lot of points!!!

Yes it's a very low solution !

maybe you could create a grid of points with the precision you are after and check for points with 0 distance from the line (or as Friou says, very small distance from the line).

Yes it is pretty much what I had in mind.

The problem is the point defintion of the grid!
Or place?

Very thanks nikos, always there to help me !!!

If you move the coordinates such that point A is at the origin, then you may be able to find a decent fraction that at least gives you an approximation to within some accuracy of the slope. You'll need to convert your floating point coordinates into integers (just multiplying by some large power of ten and rounding should do it), then you need to simplify the fraction y/x. For this you'll need to find the greatest common divisor. But even then you're likely to just end up with some huge irreducible fraction.

Hopefully that'll give you somewhat smallish integer coordinates for the slope. But then you still need to project it onto integer coordinates to undo the moving.

All probleme is here.

As is to implement a lower tolerance millimeter would be enough.

Another problem: when X is interger, Y.

In the same idea as Friou  I thinks its possible to  solve with equations.

I attached a C# script which takes a "let's just look at a limited number of values and see which one is best" approach.

Inputs:

  • Line (L)   = the line you want to simplify.
  • Step (S)  = the size of the grid whose vertices will be considered. If you want the final coordinates to be whole numbers, use Step=1, if you want them to be multiples of 2, use size=2, etc.
  • Domain (D)   = the extent in X that will be searched. The start of the domain represents the first search attempt.

The algorithm works as follows:

  • Starting at the left extreme of the search domain, a vertical line is intersected with the provided line, yielding intersection point X1.
  • The y coordinate of X1 is lowered until it is some multiple of S.
  • Another point X2 is made exactly S above X1.
  • From X1 and X2, the point closest to the line is selected.
  • If this point is closer than any existing best answer, it becomes the new best answer.
  • The search moves S units to the right.
  • Repeat until the end of the search domain is reached.

This search only looks at two potential candidates per vertical ray, so it should run in O(N), not O(N^2).

Attachments:

Notes, this is designed to work only on lines that have no Z coordinates (2D only) and it won't work for lines that are exactly vertical.

Waouh!! Big work very Fast !!!

I'll watch it carefully thank you very much David !

It's possible to add one parameter of distance ?

For my line your line it's really to far !

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service