15,121,030 members
See more:
I have this code ,I want to send pt1 and pt2 when click on button to method I have problem in prototype of pt1 and pt2
My problem is
Point pt1 = 4428900.38515348;
Point pt2 = 4428900.38515346;
Ican't set this number(double num) to this virables because the prototype of pt1 and pt2 and I want this virables have prototype Point
what is the change I should to do ?

What I have tried:

C#
```public double angleOf(Point p1, Point p2)
{
double deltaY = (p2.Y - p1.Y);
double deltaX = (p2.X - p1.X);
double result = Math.Atan2(deltaY, deltaX);
result *= (180 / Math.PI);
result += 22.5;
return (result < 0) ? (360d + result) : result;

}
private void button1_Click(object sender, EventArgs e)
{
double angle;

Point pt1 = 4428900.38515348;

Point pt2 = 4428900.38515346;
angle = angleOf(pt1, pt2);
textBox1.Text += angle;
}```
Posted
Updated 12-Feb-16 9:10am
v2
Kenneth Haugland 12-Feb-16 13:00pm

Point p1 = new Point(1,2);
_Tuba 12-Feb-16 13:07pm

I don't have (num,num) I have pt1=onenumber
Kenneth Haugland 12-Feb-16 13:21pm

Then you don't have a point with an X and Y value do you? So set the x or y accordingly: p1.X = 12.2233 etc.
_Tuba 12-Feb-16 13:29pm

sorry,Idont anderstand you :)
jeron1 12-Feb-16 13:22pm

_Tuba 12-Feb-16 13:29pm

we have PointF I dont find PointD
jeron1 12-Feb-16 13:48pm

Could you convert your doubles to floats (and vice versa)? or make your own PointD class see "http://stackoverflow.com/questions/5366659/converting-double-values-for-making-a-point-type".

## Solution 1

The standard .NET Point struct represents a point on a flat plane with an X and Y coordinate, held as integer values - there is the PointF struct, which represents the same plane, but uses floating point values instead of integers.
Neither of these are designed to hold a point on a line rather than on a plane (ie, a single number value) - so if you want to do such, you need to create your own class (or struct) and provide methods to work with them - such as AngleOf - but we can't do that for you, and you can't really "hack about" with the existing Point or PointF class to do that because all you will do is make your code hard to understand and maintain.
CPallini 12-Feb-16 15:06pm

Do you really think the OP wishes to compute the angle betweeen two points in the same line? :-)
OriginalGriff 12-Feb-16 15:29pm

No, but he doesn't really give enough info to assume anything else, particularly if you look at his angle of method, which assumes that his two points have an x and y component.
Probably, the aaaa.bbbb number is actually an xxxx.yyyy value, but it's difficult to be sure - it looks like he's copying code from different parts of the internet and assuming that they will all automatically with together if he can get it to compile... :sigh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Stefan_Lang 170 OriginalGriff 130 Richard Deeming 50 Dave Kreskowiak 40 Richard MacCutchan 30
 OriginalGriff 590 Richard Deeming 365 Stefan_Lang 170 CHill60 155 Richard MacCutchan 130

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900