question

Les-0449 avatar image
0 Votes"
Les-0449 asked ·

Integer vs single format in PointF function

I posted this initially in the wrong forum so excuse the double post.

I am working with graphing some functions and I need some clarity on the following code snippet.

 For x = -175 To 175 Step 0.1
     y = -CSng((x ^ 2) / 100)
     pts.Add(New PointF(x, y))
 Next
 gPath.AddLines(pts.ToArray())
    
    
 For x = -175 To 175 Step 0.1
     y = -CSng((x ^ 2) / 100)
     g.DrawLine(Pens.LightGray, New Point(x,-y), New Point(x, y))
 Next

In the first code snippet PoinF appears to store the X value as an integer and the Y value as a decimal number which is great, no problem.
For example the x and y values are like:

X Y
-175 306.25

but in the second code snippet New point has to be only integer??

Can someone explain to me why thats the case? Perhaps the point function allows decimals and the Drawline does not?

Or does the PointF function convert automatically to integer?

And is one method better to use then the other since I am also using antialiasing to smooth my graphing functions more smoothly?

Thank you in advance

Les

dotnet-visual-basic
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

XingyuZhao-MSFT avatar image
0 Votes"
XingyuZhao-MSFT answered ·

Hi @Les-0449 ,
Point uses integer coordinates, but PointF uses floating coordinates.
You need to use PointF parameters in Graphics.DrawLine function in your case.

 g.DrawLine(Pens.LightGray, New PointF(x, -y), New PointF(x, y))

Hope it could be helpful.

Best Regards,
Xingyu Zhao


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi X

First thx for the help in understanding this. So PointF uses floating point I got that now. So for as smooth a line I can make I should use floating point? So when things get graphed what I don't understand is since you can not have a partial pixel isn't everything converted to integer?? Just trying to fully understand.

And lastly does it matter which way I code things to produce my graph?? Code snippet 1 vs code snippet 2

Thank you

Les

0 Votes 0 ·

I believe Forms uses Point for location, and WPF uses PointF...

Somewhere in the documentation anti aliasing is mentioned with better results using PointF.

0 Votes 0 ·