|
Cloughy wrote: but more like a Rectangle root.
What is that
See my post below for an equation
Yusuf
|
|
|
|
|
Yusuf wrote: What is that
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
oh, my bad.
Yusuf
|
|
|
|
|
Welcome in the CP's Memorable Quotes list [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Don't forget - 25.8069758. That's the root of all evil.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
Nah. I was trying to lift the scientific character of this forum, now you had to butt in.
Next you'll claim 6.480740698407860230965967436088 is the solution root to most questions here.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Well it is.
|
|
|
|
|
Computafreak wrote: Multiply out the brackets:
0.75*N*N^2 = A
No, you started out with wrong equation.
Shouldn't it be
A = h * w
A = N * .75N
A = .75 * N^2
A/.75 = N^2
N = sqrt(A/.75)
we know A = 480000
N = sqrt(480000/.75 )
N = sqrt(360000 640000)
N = 600 800
[edit] modified calculation error, thanks Computafreak[/edit]
Yusuf
modified on Sunday, March 8, 2009 7:53 AM
|
|
|
|
|
My bad; I misread the equation. I've edited my post. Either way, I didn't think that 480000/0.75 was equal to 36000. Did you accidentally multiply?
|
|
|
|
|
Computafreak wrote: I didn't think that 480000/0.75
my bad, a bug in my calculation.
480000/0.75 = 640000
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Sorry for the delay in responding. You have enough information to solve this. You have two equations and two unknowns. We know the area and the width to height ratio.
So:
1.) width * height = area
2.) height = 0.75 * width
so, substituting (2) into (1)
0.75 * width * width = area
Rearranging:
3.) width = sqrt(area/0.75)
Using your numbers as an example:
width = sqrt(480000/0.75) = 800
then putting this into the height constraint:
height = 0.75 * width = 0.75 * 800 = 600
So for the 480,000 example, width should be 800, height 600. So, just solve equation (3) for the width and then plug the width result into (2) to get the height.
modified on Saturday, March 14, 2009 8:31 AM
|
|
|
|
|
Zeppelin, thank you. Just like Led Zeppelin, top of your field.
I would have never got there, but once i see it i completly understand it.
Cheers
Cloughy
|
|
|
|
|
No problem. It's what this forum is for.
|
|
|
|
|
Do you know a free Computer Graphics library complex and wide enough to make advanced artistic Computer Graphic effects?
Since it's hard to explain exactly what I'm talking about, here you can see the kind of thing I'm would like to be able to make: www.picturetopeople.org[^]. There they say it's all been made absolutely from scratch, but I'm afraid their CG libraries are not open source.
Some photo effects you can see in this address are well explained in CG text books, like the dithering, mosaic and warping ones, but there are many effects there I have never seen in books, like pencil, drawing, painting and sketch.
About text and pattern effects, maybe it's even harder. They look like drawing with very complex procedural brushes matching directional fields or so. I couldn't find advanced enough explanations to achieve that result level.
Is there any CG library able to make all of that?
|
|
|
|
|
You could take a look at the Paint.Net source code.
|
|
|
|
|
I already made it. paint.net is too much simple. It has just the trivial.
I had a look at gimp source. It's much better than paint.net, but it's still far from what I want.
I'm afraid there is no so advanced people doing open source Computer Graphics software.
Anyway, I'm still looking for.
|
|
|
|
|
hi, there
It's my first time to post a question here to ask for help because the problem is drving me crazy. Everyone who give a direct answer or redirect-url resources is appreciable.
here is the problem:
I decide to grab web-pages from a website, what my policy is that I use a main thread to find many items in a page and i send each item to a thread to deal with. So this is a parallel muti-thread problem. and I find out that the whole process stuck somewhere and the usage of the CPU climed up to 100%. here is the main code that i think is asscociated:
<pre>
HANDLE hSemaThr,hSema,hContent;
main(){
....Handle hCont=CreateFile(....);
hSema=CREATESemaphore(0,1,1,0);
hSemaThr=CREATEMUTEX(0,10,10,0);//this Semaphore is to control thread-buildings so that there are 10 threads in the process at most
WHILE(regex_search(begin,end,stringmatch,r)){
string s=stringmatch[0];
begin=stringmatch[0].second;
WaitForSingleObject(hSemaThr,INFINITE);
CreateThread(0,0,Grab,(void*)dc,0,0);
}
CloseHandle(hCont);
}
void Grab(void* doc){
......
......
WaitForSingleObject(hSema,INFINITE);
if(!WriteFile(::hCont,lpBuf,(int)strlen(lpBuf),&lpN,0)){
cout < <"can't write file in thread" < <GetLastError() < <endl;
//system("pause");
}
ReleaseSemaphore(hSema,1,0);
WaitForSingleObject(hMutexThr,INFINITE);
CanThr--;
ReleaseSemaphore(hSemaThr,1,0);
}
</pre>
Can somebody help me!
Thanks very much!
|
|
|
|
|
sorry, when i extrat my code i forget to change some words:
here is the right one and I have release the semaphore in each thread, right in front of "return", and I know the queuing policy is better but I just want to find out what's wrong with my program,by the way at the same time there can only be 10 threads because of my semaphore controling policy.see"//"
<pre>main(){
....Handle hCont=CreateFile(....);
hSema=CREATESemaphore(0,1,1,0);
hSemaThr=CREATEMUTEX(0,10,10,0);//so there are only 10 threads at most in the same time
WHILE(regex_search(begin,end,stringmatch,r)){
string s=stringmatch[0];
begin=stringmatch[0].second;
WaitForSingleObject(hSemaThr,INFINITE);
CreateThread(0,0,Grab,(void*)dc,0,0);
}
CloseHandle(hCont);
}
void Grab(void* doc){
......
......
WaitForSingleObject(hSema,INFINITE);
if(!WriteFile(::hCont,lpBuf,(int)strlen(lpBuf),&lpN,0)){
cout < <"can't write file in thread" < <GetLastError() < <endl;
//system("pause");
}
ReleaseSemaphore(hSema,1,0);
ReleaseSemaphore(hSemaThr,1,0);
return;
}</pre>
|
|
|
|
|
sorry, when i extrat my code i forget to change some words:
<pre>main(){
....Handle hCont=CreateFile(....);
hSema=CREATESemaphore(0,1,1,0);
hSemaThr=CREATEMUTEX(0,10,10,0);//so there are only 10 threads at most in the same time
WHILE(regex_search(begin,end,stringmatch,r)){
string s=stringmatch[0];
begin=stringmatch[0].second;
WaitForSingleObject(hSemaThr,INFINITE);
CreateThread(0,0,Grab,(void*)dc,0,0);
}
CloseHandle(hCont);
}
void Grab(void* doc){
......
......
WaitForSingleObject(hSema,INFINITE);
if(!WriteFile(::hCont,lpBuf,(int)strlen(lpBuf),&lpN,0)){
cout < <"can't write file in thread" < <GetLastError() < <endl;
//system("pause");
}
ReleaseSemaphore(hSema,1,0);
ReleaseSemaphore(hSemaThr,1,0);
return;
}</pre>
|
|
|
|
|
Problem:
------------------------------------------------------------------------------------------------------
Let have a sequence of K positive finite integers, starting with 1 and ending with K (each element of this sequence represents a free slot) and an arbitrary multiset of L integers of size 1..K.
Using a greedy algorithm, try to fill slots of this sequence with multiset elements, so that the sequence will be the most similar to entered multiset. Similarity is defined as a minimal sum of
absolute values of subtraction of filled sequence slots and elements, which were put in sequence slots.
Examples:
K=3
Multiset = {1,1,1}
Filled_sequence= 1[1] 2[1] 3[1]
Minimal sum = abs(1-1) + abs(2-1) + abs(3-1)= 3
K=5
Multiset = {1,2,3,4,5}
Filled_sequence= 1[1] 2[2] 3[3] 4[4] 5[5]
Minimal sum = abs(1-1) + abs(2-2) + abs(3-3) + abs(4-4) + abs(5-5) = 0
K=7
Multiset = {2,2,4,4,6,6,6}
Filled_sequence= 1[2] 2[2] 3[4] 4[4] 5[6] 6[6] 7[6]
Minimal sum = abs(1-2) + abs(2-2) + abs(3-4) + abs(4-4) + abs(5-6) + abs(6-6) + abs(7-6) = 4
K=7
Multiset = {1,1,7,7}
Filled_sequence= 1[1] 2[1] 3[-] 4[-] 5[-] 6[7] 7[7]
Minimal sum = abs(1-1) + abs(2-1) + abs(6-7) + abs(7-7) = 2
------------------------------------------------------------------------------------------------------
I could think of some greedy approaches, but cannot really determine if they really work, or even if they really are greedy. Could you write me a way, or at least idea how to implement this?
|
|
|
|
|
In order to analyse this problem more deeply we need to create the following structure.
First for each set of equal elements there is one position that is the best. For 55555 it is 3[5]4[5]5[5]6[5]7[5] and similarity is 6. If the number of elements is even we have two possibilities 7777 is 5[7]6[7]7[7]8[7] or 6[7]7[7]8[7]9[7], similarity = 4.
Now if we place every group of equal elements into their best positions and it turns out that they do not overlap, that is the best solution. But they may overlap.
*******aaaaa
**********bbbbbbb
************ccccccccc
**************ddddddddd
In that case we have to slide and cross them around to avoid overlapping but still to get the best result regarding similarity.
Now each position has its similarity value regarding the distance from the optimal 0 valued position of an element. For example for 5 and 9 we have
1 2 3 4 5 6 7 8 9 position
4 3 2 1 0 1 2 3 4 = S[5]
8 7 6 5 4 3 2 1 0 = S[9]
Once you have these values you can create a table if you like, though the table content is obvious. Now assume that multiset has these elements a1 a2 a3 a4 ... ai, repeated n1 n2 n3 n4... ni times. The table is easy to create:
0102030405060708091011...
... = S[a1]
... = S[a2]
... = S[a3]
...
... = S[ai]
Now you go: select n1 positions for element a1, then another not yet selected n2 positions for a2, then another n3 not yet selected positions for a3... and finally ni for ai.
Calculate the similarity.
Keep controllably changing selected ni positions for element ai, then for a,i-1 a,i-2.... This is simply an extend algorithm for creating combinations. You will have to check
|n over n1|*|(n-n1) over n2|*|(n-n1-n2) over n3|*|(n-n1-n2-n3) over n4|*...|(n-n1-...) over ni|
This is quite a number!
I can create heuristics but for a precise algorithm you would probably need something at least as strong as knapsack problem.
Overlapping check is something I would start with, for sure.
Another related idea is not to select all positions for one element first, but rather to select one position for a1 then one position for a2.., and so on until ai. Then to select the position for the second a1 element (if we have it), the second a2 element... second ai element. If you start this way here then you might start with placing each first element into position with value 0.
This second solution can lead to some clever heuristics.
|
|
|
|
|
One of the easy heuristics to implement is to merge two overlapping sections this way:
1. we find two sections overlapping (generally they may have different elements)
******abcdefgh**********************
**********mnopqrstuvw***************
2. make room for insertion using the most optimal way for each section (they both may slide around or whatever looks easy to implement)
********abc*d*ef**g*h****************
***********m*n**op*q*rstuvw**********
3. merge
********abcmdnefopgqhrstuvw**********
An extended heuristic, which would lead to a greedy method, is to allow in step 2. to change the order of elements in each section.
The idea is coming from almost the same problem in 2- or 3-dimension which looks very interesting
circle 1
****************
********ooo*****
*******ooooo****
********ooo*****
****************
{merge with}
circle 2
****************
******yyyy******
*****yyyyyy*****
****yyyyyyyy****
*****yyyyyy*****
******yyyy******
****************
a possible good merge:
*******************
*****yyyy**********
***yyyyyoyoo*******
**yyyyyoyoyoyoo****
***yyyyyoyoo*******
*****yyyy**********
*******************
|
|
|
|
|
Floating point values don't support bitwise operations:
CS0019: Operator '&' cannot be applied to operands of type 'double' and 'double'
CS0019: Operator '|' cannot be applied to operands of type 'double' and 'double'
CS0019: Operator '^' cannot be applied to operands of type 'double' and 'double'
which makes sense in general. I'm working on an interface that I want to have support the built-in numeric types, inluding foating point, and I want to include bitwise operations.
I could simply have the bitwise methods for floating point types throw a NotImplementedException or some such. But I'd prefer to do the best I can, so at this point I have them cast to Int64 and back; so 5.0 | 2.0 ==> 7.0
Have any of you done anything like this? What did you do? Do you find this to be a reasonable solution?
|
|
|
|
|
Is that really what you get when doing a bitwise or of the float values? IIRC they're stored as 1.01 * 2^(01) and 1.00 * 2^(01); so doing a bitwise or you should get 1.01 * 2^(11) = 10.
(all assuming my brain isn't totally fried this morning)
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
IIRC they're stored as 1.01 * 2^(01) and 1.00 * 2^(01); so doing a bitwise or you should get 1.01 * 2^(11) = 10.
It would be more natural to treat floating-point numbers for Boolean operators the same as with arithmetic operators: line up the binary point and then process them bit-wise, keeping the most significant bits of the result. Thus, e.g., 1.5 xor 4.75 would be 5.25 (001.10 xor 100.11 is 101.01). Boolean and/or/xor/andNot operators would work as expected for integers that are within precision limits. Other operators involving inversion would be problematic, however.
The difficulty is that while leading 1's can be represented by negative numbers (thanks to the fact that sum[n=0..inf](2^n)=-1) trailing 1's cannot be represented in floating-point in any manner that will persist. The floating-point value "not 0" should be "-epsilon", which should have all bits set to the left and right of the binary point. Any value--no matter how larger or small--that is and'ed with "not 0" should yield itself. The value "not 1" should have all bits set except for bit 0, and should be the same as "(not 0) - 1". And'ing any value (no matter the magnitude) with that quantity should leave all bits other than bit 0. Unfortunately, -1-epsilon is going to get rounded to -1, which will have all bits to the left of the binary point (including bit 0) set, and all bits to the right clear.
I think the Boolean operators and/or/xor/andNot could be sensibly applied to floating-point numbers, but I don't see any good way of handling the rest. Note that the normal equality (x and y)=(x andNot (-1-y)) which is applicable to integers would not apply with floats, however (with integers, 'not 0' is -1, but with floats it isn't).
|
|
|
|
|