Thomas said:
No, Im the collegue from Petra.
Okay, thank you for the clarification. So we are at least talking about
the same instance of this problem.
No first problem is, how can we figured only the List of coordinates
with or in C#?
I am having trouble with the use of the word "figure". In English, the
word has multiple meanings, including "to calculate" (e.g. "to figure
something out") and "a drawing or schematic" (e.g. "a figure eight").
It might be helpful if you can use a different word, one that has a more
precise meaning in English and which still means the same thing as you
intend.
That said...
The best is the user see like that.
-> So first we want to figured the positions.
+ P1
+P2
A cross and at the side the name of the point, how can we make that in
C#?
I'm going to assume that by "how can we make that", you are asking what
code can be written to actually draw the cross marking the point and the
label.
There are at least a couple of ways to _draw_ the cross and the name of
the point. The easiest would be to just use Graphics.DrawString() and
use a string that includes the plus symbol and the name of the point.
For example:
int ipointCur; // the current point index
string strPoint = "+ P" + ipointCur;
Then draw the string with Graphics.DrawString() at the appropriate place.
That has the drawback that you can't accurately position the plus
symbol. You can get it close, but if you need exactly accurate
rendition of the point, you'll need something that draws the cross
explicitly. You can do this using the Graphics.DrawLine() method. For
example:
Graphics gfx; // the Graphics instance; for example, taken from
PaintEventArgs
Point[] rgpt; // some array of points
int ipointCur;
Point ptCur = rgpt[ipointCur];
string strPoint = "P" + ipointCur;
// These two lines of code draw the cross
gfx.DrawLine(Pens.Black, ptCur.X - 5, ptCur.Y, ptCur.X + 5, ptCur.Y);
gfx.DrawLine(Pens.Black, ptCur.X, ptCur.Y - 5, ptCur.X, ptCur.Y + 5);
// This block of code draws the label for the point
using (Brush brush = new SolidBrush(ForeColor))
{
gfx.DrawString(strPoint, Font, brush, ptCur.X + 10, ptCur.Y);
}
The coordinatesystem, how can we figured that in C#?
0,0 (900mm,900mm)
--------------------------------------
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
--------------------------------------0,0(900mm,900mm)
Zero point can be all corners.
Again, are you asking how to draw a representation of the coordinate
system? How to exactly depends on what you want it to look like. But
at the most basic, you can just draw the lines defining the intervals of
the coordinate system. You'd use Graphics.DrawLine() for this as well,
but iterating over the range of the intervals you want to draw.
There are some details you'd have to address, related to translating the
coordinate system used for your machine to that used in the form. But
that should not be difficult. It's a simple matter of scaling the input
(which from your post appears to be in millimeters) to screen
coordinates (which by default are pixels).
What I would do is make a custom control that does all of this. It
would use its own ClientRectangle property to determine where to draw
the grid for the coordinate system. You would either always draw in
pixels, converting from the original millimeters each time you need to
specify a point, or you could (as I suggested earlier) set the
transformation of the Graphics object being used to draw so that it does
this conversion for you.
As an example of the latter, consider this code:
void MapMillimetersToPixels(Graphics gfx, Rectangle rectPixels,
Rectangle rectMm)
{
Matrix matrix = new Matrix();
float scaleX, scaleY;
scaleX = (float)rectPixels.Width / rectMm.Width;
scaleY = (float)rectPixels.Height / rectMm.Height;
matrix.Scale(scaleX, scaleY);
matrix.Translate(rectPixels.Left - scaleX * rectMm.Left,
rectPixels.Top - scaleY * rectMm.Top);
gfx.Transform = matrix;
}
That will set the transform for the Graphics instance so that you can
draw using the coordinate system defined by the rectMm rectangle in
millimeters, and that coordinate system will get mapped to the on-screen
rectangle defined by rectPixels (in pixels, of course).
Note that the Rectangle struct does not require the Left to be less than
or equal to the Right, nor the Top less than or equal to the Bottom. So
you would simply set the rectMm struct as appropriate to deal with some
sort of mapping that requires reversal of the coordinate system (as in
the case where your origin for the input coordinate system is in the
lower-right for example).
We have a list with n items. (x and y positions)
For your information, it is a machine with x and y axis.
On the axles is is a table to moves the workpiece.
If on position must be marked something.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Second we want to know the shortest way.
We must start each position in order to reduce the cycle time of the
machine.
Sounds like traveling salesman to me. As I mentioned, hopefully Fred's
reply helps with that second part of the problem.
Pete