|
|
Cool, Abhijit!
I like it.
regards,
George
|
|
|
|
|
|
Thanks Hamid,
What I want is to have open source developed based on C#.
regards,
George
|
|
|
|
|
It was good source for it and you can search for them on the Net.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Thanks Hamid!
regards,
George
|
|
|
|
|
You're welcome.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
I'm needing an algorithm for rotating points.
In my google searches, I've seen variants of this method several times:
void Rotate(ref Point p, Point centerPoint, double angle)
{
p.X = centerPoint.X + (int)((p.X - centerPoint.X) *
Math.Cos(angle)) - (p.Y - centerPoint.Y) * Math.Sin(angle));
p.Y = centerPoint.Y + (int)((p.X - centerPoint.X) *
Math.Sin(angle) + (p.Y - centerPoint.Y) * Math.Cos(angle));
}
When running this code in a loop, the radius gets smaller and smaller. Can anyone point me to a "usable" algorithm that will rotate a series of points? I know that the Matrix class has a rotate function but I would like to have more control over it.
Thanks,
Richard
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
Hi,
whenever a series of operations is executed one step at a time, without any special precautions, and having a limited precision, you will end up with unwanted results; since you are always accumulating any error, however small, in the end it will show.
In your case your points are using integer coordinates, and your (int) cast will turn floats to their
integer approximation; it is flooring the absolute value of the number, hence moving it towards zero
all the time.
Three improvements are obvious:
1.
use real rounding, rather than flooring. This may or may not help, it typically is not good enough.
2.
perform all calculations using as much precision as is available, say double, and keep your "current point" in double; when needing its integer value, cast to (int), however for the next iteration, start off with the double values.
3.
also the trig functions have limited precision; if you rotate 360 times over 1 degree, you will not end up where you started; trig functions have an intrinsic error of a few LSb (least significant bit).
Solution: don't accumulate sine and cosine results, instead accumulate the angle, which basically means
you are always rotating the starting point to its newest position in a single computation.
BTW: even if you do this, in the end your point will spiral down to the center, due to the fact that
PI cannot be represented correctly, it is transcendental after all. So while sin(2*PI) is meant to be zero, it will be slightly off, and sin(200*PI) will be even more so.
Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text (not TextBoxes), and PictureBoxes for pictures (not drawings).
modified on Friday, June 10, 2011 12:25 PM
|
|
|
|
|
Thanks for the response Luc.
Does anyone else have some code snippets that work for you in rotating an array of points?
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
There are two problems with your code:
1. As Luc already mentioned, you are casting the values to int, which accumulates rounding errors. Use PointF structures to get better resolution.
2. You are using the new value for x when calculating the value for y. You need to first calculate both x and y from the original values, then store the new values in the Point structure. Actually, instead of changing a PointF structure you should return a new PointF value from the method:
PointF Rotate(PointF p, PointF centerPoint, double angle) {
return new PointF(
(float)(centerPoint.X + (p.X - centerPoint.X) * Math.Cos(angle) - (p.Y - centerPoint.Y) * Math.Sin(angle)),
(float)(centerPoint.Y + (p.X - centerPoint.X) * Math.Sin(angle) + (p.Y - centerPoint.Y) * Math.Cos(angle))
);
}
|
|
|
|
|
I'm following now. Thanks!
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
I have an connected, open Socket with ProtocolType = IP. Before doing any sending/receiving, I try to use that Socket to Authenticate the client (in a LAN setting). I get this IOException, "Unable to read data from the transport connection: The connection was closed." When I check the Socket, Connected = True.
The code looks like this:
if (Authenticate)
{
NetworkStream clientStream = new NetworkStream(webSocket,false);
NegotiateStream authStream = new NegotiateStream(clientStream);
try
{
authStream.AuthenticateAsClient((NetworkCredential)CredentialCache.DefaultNetworkCredentials,
"",
ProtectionLevel.None,
TokenImpersonationLevel.Impersonation);
if (!authStream.IsAuthenticated)
{
Console.WriteLine("Authentication failed");
ErrorText = "Authentication using default credentials failed";
return (HttpStatusCode)(-1);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
ErrorText = ex.Message;
return (HttpStatusCode)(-1);
}
}
Any ideas?
|
|
|
|
|
How do I access a Logitech Momo wheel from C# ?
All I need is indicators for left/right turns from the wheel.
Johannes
|
|
|
|
|
Take a look at DirectInput, or XInput. For using these APIs from C# the best wrapper is probably SlimDX.
|
|
|
|
|
Hi
I have successfully applied the networking logic using TCP and UDP protocols both while on internal LAN scenario. Now how can I connect to the computer on network i.e. send a text message to another computer on the internet.
The target computer has the local ip address of 10.10.20.200 which is assigned from a local LAN server which is connected to the internet (you can think of a router too) now I dont know how to access that computer where a server is residing which will receive the message sent from the client.
Hope I was clear to illustrate the scenario and my question.
Regards,
Mujtaba Panjwani
Tiger Softwares
Software Designer and Developer
VB.NET, C#, ASP.NET, VFP
|
|
|
|
|
You need to look up NAT[^]
|
|
|
|
|
Hi
Thanks for the reply.
Can you please give me an example of how to discover NAT for the exact computer, I was thinking of a way to make the program work exactly as yahoo or msn messengers does i.e. sending a message to other computer or sending a file etc.
I will be very thankful for your help.
Regards,
Mujtaba Panjwani
Tiger Softwares
Software Designer and Developer
VB.NET, C#, ASP.NET, VFP
|
|
|
|
|
I'm trying to collect the values from a datagridview in a child form and place them in textboxes located in it's parent form.
I'm using the following statement for one of the values:
txtFirstName.Text = this.finder.dataGridView1.SelectedRows[0].Cells["firstNameDataGridViewTextBoxColumn"].Value.ToString();
As far as I can tell, it should be working. When I run the program, once it gets to this point it throws an error telling me that the values are null. There are no spelling errors.
"finder" is the child form.
Please help.
|
|
|
|
|
Have you tried determining which part of the statement is null?
Are you trying to just get the first selected row and are you sure there is a row selected?
|
|
|
|
|
Sorry, maybe I'm misunderstanding the error message. It's not exactly telling me the value is null...
The message I'm getting is, "Object reference not set to an instance of an object."
It's pointed at "firstNameDataGridViewTextBoxColumn".
After some testing I'm finding the same error on my search statement to fill my datagridview, now, as well:
this.finder.customerTableAdapter.FillByFirstLastPhoneNo(this.finder.edsDBDataSet.Customer, txtLastName.Text, txtFirstName.Text, txtPhone.Text);
If I catch it, however, it continues and fills the datagridview normally, dispite throwing this exception.
I'm still pretty green with this, unfortunately. I'm really not quite sure what exactly is going wrong, since it didn't have this problem earlier.
|
|
|
|
|
The error message usually means that one of the objects has not been created. This could be due to the column not existing or rows not being selected.
Are you checking that SelectedRows.Count is greater than 0? If there are no explicitly selected rows then this could be the problem.
|
|
|
|
|
It looks as though the problem lies in my sql query. I'm not sure how it went wrong, since I've been using it successfully for a week. Reconfiguring the query has not helped, either.
My query is as follows:
SELECT Address, Customer_ID, First_Name, Last_Name, Phone_No FROM Customer
WHERE (Last_Name LIKE @Last_Name) AND (First_Name LIKE @First_Name) AND (Phone_No LIKE @Phone_No)
called by the code I posted previously:
this.finder.customerTableAdapter.FillByFirstLastPhoneNo(this.finder.edsDBDataSet.Customer, txtLastName.Text, txtFirstName.Text, txtPhone.Text);
Thank you for trying to help thus far. I'll keep working on this; maybe someone will have some insight on what's going wrong.
|
|
|
|
|
Dear Sirs:
I have a C# application with a ToolStrip control and a RichTextBox control.
Three of the buttons are for aligning the text, i.e., Align Left, Center, Align Right.
And two of the buttons are for increasing and decreasing Indentation.
I have the CheckOnClick property set to true for these buttons.
My application also has formatting buttons, i.e., Bold, Italic, Underlined and one button for setting a bulleted style.
It was previously suggested that I use the RichTextBox_SelectionChanged event, which in fact works for the formatting buttons and Bullets button.
However, I am running into a dead-end when attempting to write code for the alignment buttons or the 2-Indentation buttons. For example, when I try something like the following code:
<pre>tsBtnAlignLeft.Checked = richTextBoxBody.SelectionAlignment;
tsBtnAlignCtr.Checked = richTextBoxBody.SelectionAlignment;
tsBtnAlignRight.Checked = richTextBoxBody.SelectionAlignment;</pre>
it throws this exception:
"Cannot implicitly convert type System.Windows.Forms.HorizontalAlignment' to 'bool'"
And when I try to add further code in the RTB's SelectionChanged event for the IncreaseIndentation or DecreaseIndentation button's, i.e.,
<code>tsbtnIncreaseIndent.Checked = richTextBoxBody.SelectionIndent;</code>
it throws the following exception:
"Cannot implicitly convert type 'int' to 'bool'"
Can anyone provide a suggestion for getting the Checked property of the alignment buttons and the indentation buttons to reflect the contents of the RichTextBox as the cursor moves over text that is aligned and\or indented?
Thank you in advance.
Richard
|
|
|
|
|
In the SelectionChanged event you will need to analyze the selection alignment and set the Checked property of the left/right/centered buttons to suit.
This is because the SelectionAlignment property can be more than just true or false (boolean), where the checked property is a boolean.
|
|
|
|
|