
marca292 wrote: number of bytes = ((number of bits)* 7) / 8
It should really be (note the plus sign)
number of bytes = ((number of bits) + 7) / 8 to round up any odd bits to a byte boundary.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.





Is there a generic algorithm for ordering noncrossing (poly) lines? The "order" is hard to define, but any child could do it if they saw the lines drawn on paper...from the first line, to the last line, the inside line to the outside line etc. The order might endup being L>R or T>B or somewhere in between.
I'm thinking you might be able to work with the distance to the line end points from the centroid of all the lines...or something like that.
Do the end points with the "extremeest" coordinates, definitely locate the "first" and "last" lines?
Anyone?





This is a partiallyordered set. One line can come before another, or they may be incomparable. You can choose whatever heuristic that makes sense for your application for ordering them.
"Microsoft  Adding unnecessary complexity to your work since 1987!"





I have a set of parallelish lines (they may not be parallel, but they don't cross) that define an area. On each line, I calculate two points (lets say P1 and P2) which define an operating region. With an ordered set of lines, I know for line 1 (L1), the polygon showing the operating region starts at P1 and ends at P2. The next point in the polygon is L2P1, whereas the (n1)th point is L2P2 (where n is the number of lines I have).
My problem is:
1) Lines may be drawn either way, so P1 and P2 in two 'adjacent' lines may not be on the same side.
2) Lines may not be in order.
So, knowing the number of lines, and which points belong to the same line (i.e., I know which points are paired),
can I calculate the order of the lines / points, so that I can draw my polygon?
It seems like a hulling problem, but is there a way to say 'all these points are on the hull boundary'?
Wouldn't that lead to multiple solutions for certain sets of points?





Actually  is this a travelling salesman problem?





Can you show some diagrams of the possible scenarios? I'm not sure I have it entirely clear in my head.
If the hull is known to be convex, and we're talking 2D, I would take an approach like:
 find a point inside the shape (the average location of all the control points should do)
 go around the control points in order of angle from that central point
I don't think the pairing of points on the same line matters, once you have the collection of points.





This is a very simple example, but I want to draw the polygon defined by the black lines and the green and red spots.
This[^]





Okay, so if you can find that it's the green and red lines you want, my solution will work for creating the polygon. (The average point will be somewhere in the middle and then G1, R1, R2, G2 are in order of angle from it.)
To find which lines you want, order them based on how far along the 'black axis' they cross the black lines, i.e. by r.b where r is any point on a line and b is the direction vector of the black lines.
(Sorry for not responding for a while, I forgot about this forum.)





Thanks  that just leaves me with the ordering problem (see my other post). Since my lines may have been draw either way around, and in a "random" order...ordering them is not as easy as it sounds. I've come up with a method that will work most of the time (I think) (Here[^]).
I think throwing the points at a Travelling Salesman algorithm might be less complicated.





Kyudos wrote: I think throwing the points at a Travelling Salesman algorithm might be less complicated.
No need for that. When the lines are almost parallel, and don't cross each other, you can define some kind of distance, calculate that, and order them all based on it.
Example: take one of the lines, calculate its equation in the form f(x,y)=a*x+b*y+c.
All points on the line itself have f(x,y)=0 by definition.
The green/red points have a nonzero f value, take one of them, or the average, and use that as a distance.





I think that is along the lines of what I described in my Physics Forum post (see above). But a TSP solution will generically work for both lines and polylines with minimum complication.





I answered that as well in the last paragraph . I'm assuming that the black lines are in some known direction, otherwise you have to pick a direction vector ... but just choosing the perpendicular to any one of the lines should work fine. It doesn't actually matter whether the order ends up as ABCD or DCBA, and picking a perpendicular will guarantee one of those will be the case if the lines are close to parallel. (The average perpendicular for all the lines will be better but probably unnecessary.)





I have to write a program in java for wordwrap with minimum regard...
for example if we have "aaa bb cc ddddd" and want to wrap it in lines with this method the final form should be like this :
 Line width: 6
aaa Remaining space: 3 (cost = 3 squared = 9)
bb cc Remaining space: 1 (cost = 1 squared = 1)
ddddd Remaining space: 1 (cost = 1 squared = 1)
attention that we don't know number of lines...I don't understand the algorithm which is in wikipedia ,in this link :
http://en.wikipedia.org/wiki/Word_wrap[^]
but unfortunately I still have problem with understanding the algorithm...can some one explain it with example for me ?





You have already asked this question in Q&A. Read the guidelines, and ask your question ONCE if you don't want to annoy people who might otherwise have an answer for you.
Software rusts. Simon Stephenson, ca 1994.





Hi...I wanna write a program in java that can count the number of balanced matrix of N*N...the only way that I know is to consider all the possible assginments for the matrix and then choose the answers...I searched the topic and found something about it in wikipedia...it solved the problem with dynamic programming but unfortunately I don't understand exactly the algorithm...can anyone help and explain completely with example for me what to do ?
this is the link that I found :
http:





Dynamic programming can be used when optimal solutions are composed of optimal subsolutions. You start with the smallest optimal subsolutions, and use them to build up optimal solutions to larger subproblems.
This typically runs in polynomial time, which is faster than trying all possible solutions, which would take exponential time.
"Microsoft  Adding unnecessary complexity to your work since 1987!"





plz can anyone tell me how to store the data in text file using file handling in java...
plx Mail me comprehensive program of file handling, explain with comment and few of explanation...
asadali.nazir@gmail.com





See here[^] for all the information you need.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation  Len Goodman





Unless you want a lot of spam in your inbox, please do not put your email address in a message posted publicly.
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare





This article: Graphical solution to eight queen problem[^] mentions "the old algorithm from HorowitzSahani". Does anyone here have more information on this? I haven't found anything online, I'm thinking it's only in a text book.






Ah, good, thanks. That first one still just shows the snippet* posted in the article I mentioned, I was hoping to see more on the algorithm.
* And that's what I came up with on my own last week.
Also, I note in the second one that he's using recursion  my algorithm is nonrecursive.
P.S. I just ordered a used copy of that book from Amazon.
modified 1Jan12 10:27am.





I would be interested in seeing your algo to see how it stacks up with some of my algos for removing recursion.
Dave.





Once I've seen what's in the book I'll decide whether or not mine is unique enough to form an article.





The book arrove today. My code is very much like the code they show on page 338 with two main differences:
0) They have the test in a separate function and therefore a global array.
(Which also has a needless call to ABS .)
1) They have an extra while loop.
public static System.Collections.Generic.IEnumerable<System.Collections.Generic.IList<int>>
nQueens
(
int HowMany
)
{
int[] board = new int [ HowMany ] ;
int row = 0 ;
board [ row ] = 1 ;
while ( row >= 0 )
{
board [ row ]++ ;
if ( board [ row ] == HowMany )
{
row ;
}
else
{
int i ;
for ( i = 0 ; i < row ; i++ )
{
int diff = board [ row ]  board [ i ] ;
if ( ( diff == 0 )  ( System.Math.Abs ( diff ) == ( row  i ) ) )
{
break ;
}
}
if ( i == row )
{
row++ ;
if ( row == HowMany )
{
yield return ( System.Array.AsReadOnly ( board ) ) ;
row ;
}
else
{
board [ row ] = 1 ;
}
}
}
}
yield break ;
}



