|
There's a lack of requirements: system has two degrees of freedom ({x,y} with constraints, though) and your requirements provide only one value.
For instance, you may choose to put all of the points at fixed angle, say 45°, using the following formula:
x(n)= y(n) = (100.0 - n) / (100 * pow(2,.5));
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]
|
|
|
|
|
Thanks for ur quick responce. here is the clarificatio of the question
I will have a values from 0 to 100.
I will get the data ramdomly ranging from 0 to 100
Which i need to place them in a 90deg ARC. 1/4th of circle
means i need to draw a point in that 90deg arc wrt the value i received.
To draw that i should know the x and y coordinates.
Ex
if the value is zero it should draw in the Center of the circle( means in the corner of the 90 deg ARC)
if the value is 50 it should draw in the middle of the ARC
if the value is 100 it shold draw of the circumference of the circle/ ARC
|
|
|
|
|
pallaka wrote: if the value is zero it should draw in the Center of the circle( means in the corner of the 90 deg ARC)
if the value is 50 it should draw in the middle of the ARC
if the value is 100 it shold draw of the circumference of the circle/ ARC
This is the opposite of the previous post (wherein you stated 100 should be at the circle center). Anyway it is not difficult to place the point onto the ray
(assuming ray=1 )
x(n) = (n * cos(angle)) / 100;
y(n) = (n * sin(angle)) / 100;
But what to do with angle (since you left this degree of freedom free...)?
You may pick a random value or do you want to choose a fixed one (you put only the constraint 0° <= angle <= 90° )?
BTW: If you need to populate randomly (and uniformly) a circular sector, well, that's a completely different matter!
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]
|
|
|
|
|
thanks a lot it resolved my problem
|
|
|
|
|
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]
|
|
|
|
|
It will be difficult. Because i am drawing the points after i get X,Y coordinates so it is overlapping the drawing. i need to differentiate the angle wrt to the value i receive
|
|
|
|
|
Hello everybody,
is there a tool/utility to convert a unicode file in uppercase and then
to an ascii file with html encoding (i.e. ł...)?
Thanks,
Michela
|
|
|
|
|
Not sure of any particular tool, but writing your own shouldn't be that difficult.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I am so nice I wrote a utility method for you:
static public void ProcessFile(string inPath, string outPath)
{
using (StreamReader r = File.OpenText(inPath))
using (FileStream f = File.Create(outPath))
using (StreamWriter w = new StreamWriter(f, Encoding.ASCII))
while (!r.EndOfStream)
w.WriteLine(HttpUtility.HtmlEncode(r.ReadLine().ToUpper()));
}
This assumes it's alright to process the file line by line; I did it because it saves a few lines of code. If your file doesn't contain many lines you should consider reading blocks of characters instead - this ensures that the methods memory footprint stays the same regardless of the file fed to it. It also makes for more efficient memory allocation since you can then reuse the same allocated character array for each read (whereas readline allocates a new string each time).
HTH
|
|
|
|
|
I've created a wrapvalue function in C#, but I can't figure out how to make it work with a lower bound, like a negative.
Here's the function at the moment:
private int WrapValue( int val, int upperBound ) {
return val - ( upperBound * ( val / upperBound ) );
}
WrapValue( 1023, 360 ) would return 303.
By the way ( val / upperBound ) is integer division.
It works great for positive values, but not negatives and you can't specify a lower bound. Does anyone know how I to make it work with negatives and a lower bound so I could do something like this:
WrapValue( int val, int lowerBound, int upperBound )
WrapValue( -300, -500, 123 )
Thanks in advance.
By the way I'm using this to scroll a semi-transparent image over another image in the shape of a circle to create the illusion of a rotating sphere. The semi-transparent image needs to wrap around in a certain way and this function will help me accomplish that if I can get working correctly.
modified on Sunday, July 20, 2008 5:19 PM
|
|
|
|
|
Hi,
what you are trying to achieve is to alias an original value into a range [low,high);
the way to achieve that is by adding/subtracting high-low as often as is required
to get the value inside the given range.
We know that (for integers and with b>0) a-a/b*b returns a number in [0, b)
that is the range including 0 and up to but excluding b.
And the modulo operator does exactly the same: a%b gives the remainder of a/b
So it will look like
newValue=origValue-(origValue-low)%(high-low)
[ADDED] above formula is wrong, both test cases don't detect it.
It should be: newValue=low+(origValue-low)%(high-low)
[/ADDED]
Fast proof (using diff for high-low):
1. for origValue=low, newValue=origValue-0*diff which equals low
2. for origValue=high, newValue=origValue-1*diff which equals high-(high-low)
hence low as it should
You'll have to check the behavior for negative numbers, I expect it to be all right.
modified on Sunday, July 20, 2008 6:01 PM
|
|
|
|
|
hmmm...
When I try this function:
private int WrapValue( int val, int lowerBound, int upperBound ) {
return val - ( val - lowerBound ) % ( upperBound - lowerBound );
}
with:
WrapValue( 1023, 0, 360 ) I get 720 as a result.
when I try this function:
private int WrapValue( int val, int lowerBound, int upperBound ) {
return val - ( val - lowerBound ) / ( upperBound - lowerBound );
}
with:
WrapValue( 1023, 0, 360 ) I get 1021 as a result.
But, shouldn't I be getting 303 still?
I haven't tried with negatives or a different lower bound yet.
|
|
|
|
|
Hi,
sorry my mistake, the formula should be:
newValue=low+(origValue-low)%(high-low)
which really means wrap around every high-low, but perform an offset of low
In your second snippet, you had / again instead of %
|
|
|
|
|
Well it's closer...
Using this function:
private int WrapValue( int val, int lowerBound, int upperBound ) {
return lowerBound + ( val - lowerBound ) % ( upperBound - lowerBound );
}
WrapValue( 1023, 0, 360 ) gives me 303.
But WrapValue( -5, 0, 360 ) gives me -5, but it shouldn't it give me 355?
|
|
|
|
|
OK,
This page[^] explains a bit about modulo for negative numbers.
Seems like in C# a%b will return in (-b,0] for negative a, always assuming positive b.
To fix this, you will need a conditional test.
Either check for origValue<low and="" use="" another="" formula="" if="" it="" mode="hold">or keep the formula, and add another diff if it resulted below low.
As a hack, you could forget the test, and start of with originalValue+99999*(high-low)
but doing so reduces your useful range and/or risks an overflow, which would ruin
everything.
|
|
|
|
|
So I could check to see whether originalValue is negative or not and if it is I do what?
|
|
|
|
|
if the result is less than low, adding another high-low
seems the easiest way of dealing with it.
|
|
|
|
|
Nice, it works
The function:
private int WrapValue( int val, int lowerBound, int upperBound ) {
int result = lowerBound + ( val - lowerBound ) % ( upperBound - lowerBound );
if( result < lowerBound ) {
result += ( upperBound - lowerBound );
}
return result;
}
I tried it with all different bounds and values and it works great.
Thanks a ton
|
|
|
|
|
|
sadiyaVasanthKumar wrote: Postfix Multidigit Expression Evation in C#
You left out the 'lua' - does that help?
What was the question??
Maybe lua[^] is the answer?
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."
|
|
|
|
|
Actually he is missing an "alu"[^].
|
|
|
|
|
Agreed, since there was no logic in the OP
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I can't seem to figure this out...
I have a value within the range of 0 to 40 and I want to be able to convert that into a value in the range of 0 to 10,000.
This is for a simple music player that I have built into one of my programs. I'm using C# and DirectX.AudioVideoPlayback to play mp3 files. I have a working custom slider control that has a range from 0 to 40. This will be used to adjust the volume of an mp3.
The problem is that volume in DirectX.AudioVideoPlayback ranges from 0 to 10,000 (technically -10,000 to 0... 0 being max volume). Therefore I need to figure out a formula to convert a value from my custom slider control that is in the range 0 to 40, to a value DirectX.AudioVideoPlayback can use which is in the range of 0 to 10,000. Also these values are integers and the conversion doesn't have to be exact, just close enough.
I'm bad at math, so any ideas?
|
|
|
|
|
did you consider multiplying by 250?
|
|
|
|
|
Nice, it works. So 10000 / 40 = 250... I knew it was something simple.
Thanks a ton
|
|
|
|