Transforming polygon coordinates?

A

Adam Clauss

I have a list of points (their coming in as decimal types, I can convert to PointF) that I am trying to draw to a form.

Unfortunately, the coordinate system these points are coming from is not like Windows Forms use. Instead of (0,0) being the top
left, (0,0) is in the "standard" graph position in the center of the coordinate plane. (So we have positive and negative values on
both the x- and y- axis).

Is there a "good" way to convert these points to the coordinate system so I can draw them using DrawPolygon, or do I have to do all
the conversion by hand?
 
D

David Browne

Adam Clauss said:
I have a list of points (their coming in as decimal types, I can convert to
PointF) that I am trying to draw to a form.

Unfortunately, the coordinate system these points are coming from is not
like Windows Forms use. Instead of (0,0) being the top left, (0,0) is in
the "standard" graph position in the center of the coordinate plane. (So
we have positive and negative values on both the x- and y- axis).

Is there a "good" way to convert these points to the coordinate system so
I can draw them using DrawPolygon, or do I have to do all the conversion
by hand?
Use transforms to transform the coordinate system.

http://msdn.microsoft.com/library/d...us_global_and_local_transformations_about.asp

Or just use the matrix representation of a transform to transform the
verticies in your polygon onto the "standard" windows forms coordinate
system.

David
 
R

Robby

One way of doing this is you can use the Graphics.ScaleTransform and
Graphics.TranslateTransform methods to invert the y-axis and move the origin
to the center of the form. You can then use DrawPolygon with the original
PointF array.

Robby
 
B

Bob Powell [MVP]

The GDI+ FAQ has an article on drawing text on an inverted axis which shows
how to create a transform to re-arrange the axes of the window to the system
you're using.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Adam Clauss said:
I have a list of points (their coming in as decimal types, I can convert
to PointF) that I am trying to draw to a form.
Unfortunately, the coordinate system these points are coming from is not
like Windows Forms use. Instead of (0,0) being the top
left, (0,0) is in the "standard" graph position in the center of the
coordinate plane. (So we have positive and negative values on
both the x- and y- axis).

Is there a "good" way to convert these points to the coordinate system so
I can draw them using DrawPolygon, or do I have to do all
 
A

Adam Clauss

OK, (I'm new to going through this transforming of points...). I created a small demo of just taking a single line and using
ScaleTransform and TranslateTransform and I saw what effects it has.

The problem I'm running into. The points I'm using are a subset of a MUCH larger "graph" and as a result the points are very large
(on the order of 10^15 or 10^15 in many cases, sometimes even bigger).

I've looked into TransformPoints()... do I need to do something here before I can draw it?

Sorry, I've tried doing all these calculations by hand, and I've completely confused myself on what I need to accomplish to convert
the very large positive/negative values to much smaller 0-based (positive) numbers.

--
Adam Clauss
(e-mail address removed)
Robby said:
One way of doing this is you can use the Graphics.ScaleTransform and Graphics.TranslateTransform methods to invert the y-axis and
move the origin to the center of the form. You can then use DrawPolygon with the original PointF array.

Robby
 
R

Robby

You will have to use ScaleTransform to adjust the scale. For example, if
your maximum absolute value of your points Y value is yAbsMax, half your
client size height is clientHeight / 2.0F and the origin is at the center of
the client area; also if your maximum absolute value of your points X value
is xAbsMax, half your client size width is clientWidth / 2.0F and the origin
is at the center of the client area; then

Graphis.ResetTransform()
Graphics.ScaleTransform( _
(1.0F / xAbsMax) * (clientWidth / 2.0F), _
-1 * (1.0F / yAbsMax) * (clientHieght / 2.0F))


One other thing, do the ScaleTransform first then do the TranslateTransform
with MatrixOrder.Append as the last param.

Graphics.TranslateTransform(clientWidth / 2.0F, _
(clientHieght / 2.0F), MatrixOrder.Append)


All this is in VB type syntax. I am VB. :)

Robby


Adam Clauss said:
OK, (I'm new to going through this transforming of points...). I created
a small demo of just taking a single line and using ScaleTransform and
TranslateTransform and I saw what effects it has.

The problem I'm running into. The points I'm using are a subset of a MUCH
larger "graph" and as a result the points are very large (on the order of
10^15 or 10^15 in many cases, sometimes even bigger).

I've looked into TransformPoints()... do I need to do something here
before I can draw it?

Sorry, I've tried doing all these calculations by hand, and I've
completely confused myself on what I need to accomplish to convert the
very large positive/negative values to much smaller 0-based (positive)
numbers.
 
A

Adam Clauss

OK, I'll give that a shot - and translating from VB is not a problem :)

Thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top