|
Simple way:
Assuming
r = random number from 0 to 1
Xmin and Xmax = limit value of X
Ymin and Ymax = limit value of Y
Then
generate X = Xmin + r * (Xmax - Xmin) [and Y = Ymin + r * (Ymax - Ymin) ]
test if the distance from (X,Y) to the last valid (X,Y) generated is great than a the desired value, if not generate another point (X,Y)
Complex way:
Use the polar coordinates (it will become a not uniform distribution)
Start point is the last valid point (X,Y) found, now you need to generate the new point as a direction and a distance to move it.
First generate a random angle uniformely from 0 to 360 degrees.
Then generate a random distance uniformely from a minimal to a maximal distance: the minimal distance is the desired minimal distance from 2 consecutive points. The max distance is the simple calculation of the border of the rectangle moving with the found angle.
(when the maximal apceptable distance is less then the minimal distance then this means that this angle is not valid, the rectangle border is too near,...so the solution is simply to generate another random angle value)
Russell
|
|
|
|
|
3d table cells. Easy. Mid grey for the cell. Light grey - top / left borders. Dark grey - bottom / right borders. Easy. Greys are easy in RGB though - keep R G B the same , ie EE EE EE - very light grey. 11 11 11 - very dark grey.
Now - I want a 3d blue cell, or a 3d orange cell, or a 3d slightly purple cell. I know the colour of the cell, but what formula can I apply to 'lighten' this colour for the highlight, and darken for the shadow....
On your marks....get set....[reply from Luc / CPallini....damn - that was quick]
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|
|
|
Sorry, I am having an off day.
What can I add to ingc's reply? In Java the Color class has methods that return
a lighter/darker shade of a given color, unfortunately .NET does not offer this.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: unfortunately .NET does not offer this
In .NET the Color class doesnt do that, but there is a class ControlPaint (in System.Windows.Forms) that offers the static methods Dark(), DarkDark(), Light(), LightLight()
|
|
|
|
|
I just discovered this myself.
I am not sure the results are good enough, seems like they took the easy way out
(without much HSL conversion); DarkDark as far as I can see is always Black ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: I am not sure the results are good enough
You are right about the quality. But you can be lazy (ControlPaint) or good (do it your own way).
|
|
|
|
|
Researchers in England may have finally settled the centuries-old debate over who gets credit for the creation of calculus.
For years, English scientist Isaac Newton and German philosopher Gottfried Leibniz both claimed credit for inventing the mathematical system sometime around the end of the seventeenth century.
Now, a team from the universities of Manchester and Exeter says it knows where the true credit lies — and it's with someone else completely.
Article[^].
|
|
|
|
|
Hi,
this may interest me, unfortunately Internet Explorer 6.0 crashes on the link.
Firefox survives it tho.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: this may interest me, unfortunately Internet Explorer 6.0 crashes on the link.
Hmmm, it was fine for me and I was using IE...
|
|
|
|
|
All they say in that article is that they discovered an infinite series without saying what it was. I don't really see what infinite series has to do with calculus. I think I'd need a more more information than that before I could judge wether they had really discovered calculus. The positive integers from 1 to infinity are an infinite series and I wouldn't rate them highly for discovering that.
|
|
|
|
|
A Noteworthy Programmer wrote: I don't really see what infinite series has to do with calculus.
Just about everything, actually...
|
|
|
|
|
Infinite series are used for way more that just calculus. Calculus is involved with the study of what happens when you let the step sizes used in area calculations and gradient calculations and such like become infinitlely small.
An infinite series is genereally any equation who's terms go forever, which could be like the series 1/2+1/4+1/8+... etc...
Anyway my main point is that they didn't really say what those Indian mathematicians had discovered which is what I was really interested in knowing on reading that article. Maybe this news item is on some other web site with more information?
|
|
|
|
|
Actually searching the web lead me to this article on wikipedia that explains about some of the stuff they did:
http://en.wikipedia.org/wiki/Kerala_school_of_astronomy_and_mathematics
It seems they developed the equations for the sine & cosine function and others.
|
|
|
|
|
A Noteworthy Programmer wrote: nfinite series are used for way more that just calculus. Calculus is involved with the study of what happens when you let the step sizes used in area calculations and gradient calculations and such like become infinitlely small.An infinite series is genereally any equation who's terms go forever, which could be like the series 1/2+1/4+1/8+... etc...
What are you telling me this for? I'm a theoretical physicist!
A Noteworthy Programmer wrote: Anyway my main point is that they didn't really say what those Indian mathematicians had discovered which is what I was really interested in knowing on reading that article. Maybe this news item is on some other web site with more information?
I posted it here for general interest. I'm sure if you search the math periodicals from a university website you can probably locate an article of some kind by searching for the authors...
|
|
|
|
|
73Zeppelin wrote: What are you telling me this for? I'm a theoretical physicist!
Thats funny, I used to work in Physics! I worked at this place called JET near Oxford in England that researched nuclear fusion. I used to program in FORTRAN, a language that you hardly ever here about these days.
Nowadays though, I program computer games for a living and genereally in C++.
|
|
|
|
|
The integral is an infinite sum of infinitesimally small numbers.
Edit: And the general solution to the value of a converging infinite series is done via integration.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
I thought that was known for a long time ???
Me think "inventions" such as these were invented pretty much everywhere at about the same time; maybe was are to believe it was invented by an occidental (European) because they were the ones to "formalize" it and that the means of knowledge distribution was only better there than, for example in India or China or maybe in South America.
Also, the colonization of India and the rest of the world by Europeans might have try to erased some part of history that made them looked "bad" or "retarded" in some fashion compared to the cultures they colonized.
|
|
|
|
|
|
I thought it was, "the first caveman who threw a spear".
|
|
|
|
|
My mathematical skills are weak but I need to calculate a week number based on a date. The week number will be either 1, 2, 3 or 4.
I have a base date for a week 1 within the calendar year, which is always a monday, for example 15th Jan 2007.
Therefore, if I enter a date of 22nd Jan 2007 I need a return value of 2 representing week 2, likewise for 23rd through to 28th Jan 2007. 29th Jan 2007 through to 4th feb 2007 would return week 3 and so on.
Just to clarify my calendar is divided in 4 weekly cycles, and I need the week within the 4 weekly cycle that a date falls in.
I would be grateful for any assistance on creating a formula to provide this information.
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
Exactly how you do this depends on the language / support for calculating differences between dates. The formula you want is:
week number = ( ( (day(date) - day(base)) / 7 ) % 4 ) + 1
where day(date) - day(base) is the number of days difference between 'date' and 'base', and is assumed to be an integer.
e.g.: day(tomorrow) - day(today) = 1
% is the remainder operator in C/C++, so 4%4 = 0, 5%4 = 1, 6%4 = 2, 7%4 = 3 and so on
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Thanks Peter, you're the best.
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
I have a 64 bit integer (C# long). Apparently the file format I'm writing (Internet Explorer cookies) wants the "high part" and the "low part." I'm pretty sure that the low part is just thingy >> 32. What about the high part...?
My integer is signed.
Thanks!
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
Hi,
that would be wrong.
the low part is the result of anding with a mask containing the bits you want,
for 64-bit that would be 0x00000000FFFFFFFFL (L suffix for ulong).
[Addition: the alternative is to cast to (uint)]
the high part is what you get if you right-shift an unsigned long
over 32 positions;
or simply cast to uint
The fact the Intel and the like store numbers the other way around has nothing
to do with it, since you are performing mathematical operations here, not
memory access operations.
I trust you could have figured this out yourself with a couple of small experiments ?
-- modified at 3:40 Friday 3rd August, 2007
|
|
|
|