Calculating point on a circle's circumference from angle in C#?
You forgot to add the center point:
result.Y = (int)Math.Round( centerPoint.Y + distance * Math.Sin( angle ) );
result.X = (int)Math.Round( centerPoint.X + distance * Math.Cos( angle ) );
The rest should be ok... (what strange results were you getting? Can you give an exact input?)
Find the point on a circle with given center point, radius, and degree
The simple equations from your link give the X and Y coordinates of the point on the circle relative to the center of the circle.
X = r * cosine(angle)
Y = r * sine(angle)
This tells you how far the point is offset from the center of the circle. Since you have the coordinates of the center (Cx, Cy), simply add the calculated offset.
The coordinates of the point on the circle are:
X = Cx + (r * cosine(angle))
Y = Cy + (r * sine(angle))
Finding the coordinates on the edge of a circle
Here's the mathematical solution which can be applied in any language:
x = x0 + r * cos(theta)
y = y0 + r * sin(theta)
x0
and y0
are the coordinates of the centre, r
is the radius, and theta
is in radians. The angle is measured anticlockwise from the x-axis.
This is the code for C# specifically if your angle is in degrees:
double x = x0 + r * Math.Cos(theta * Math.PI / 180);
double y = y0 + r * Math.Sin(theta * Math.PI / 180);
Calculate points coordinates of an arc
DrawArc draws a part of an ellipse or a circle in your case (regarding the 4th and 5th parameter.) The radius of your circle is 25. The math of a circle is: x^2 + y^2 = r^2
.
Therefore, I think you can calculate points on this circle by calculating:
Y = myPoint.Y + 25 +/- Sqrt(625 - (X - myPoint.X - 25)^2).
Let X run from myPoint.X
to myPoint.X + 50
and you will find some corresponding Y's.
Because it is a circle, each X has 2 Y values (Therefore, +/- in the formula; you need to calculate the + and the -).
c# Calculate a 3D point from starting 3D point using distance and angles
Are you sure the values of edge3D[0] and edge3D[1] are correct? They would be if you had just 2 dimensions, but if you have a 3-dimensional vector of length 'radius' sticking up and to the side at some angle, then the length of its projection onto the surface will be shorter.
First you should calculate the length of the projection of the vector onto the flat surface:
double radius2D = radius * Math.Cos(verticalAngle);
Then you can calculate the horizontal coordinates in a similar way to your code:
edge3D[0] = center3D[0] + radius2D * Math.Cos(horizontalAngle);
edge3D[1] = center3D[1] + radius2D * Math.Sin(horizontalAngle);
And finally calculate the "height" of the vector:
edge3D[2] = center3D[2] + radius * Math.Sin(verticalAngle);
EDIT: in the code above I assume that horizontalAngle and verticalAngle are in radians. If they are in degrees, then you should make a conversion to radians just like you do it in your code.
Get the angle and the distance of point from center point
to find angle between center and the point in radians:
Math.Atan2(point.y-center.y,point.x-center.x)
normalize it:
Math.Atan2(point.y-center.y,point.x-center.x)/Math.PI/2
make it start from top:
Math.Atan2(point.y-center.y,point.x-center.x)/Math.PI/2+0.25
don't let it go below zero:
(Math.Atan2(point.y-center.y,point.x-center.x)/Math.PI/2+0.25+1)%1
invert it so it goes counterclockwise:
1-(Math.Atan2(point.y-center.y,point.x-center.x)/Math.PI/2+0.25+1)%1
you can rewrite it as:
1-(Math.Atan2(point.y-center.y,point.x-center.x)/2/Math.PI+1.25)%1
Find points on edge of screen with an angle and radius
The line from the origin can be expressed by the equation
y = mx
where the slope m = y3/x3. You will need a line perpendicular to your first line, which means it has a slope of
m' = -1/m
Therefore it can be expressed by the equation
y = m'(x-x3) + y3
The point (X1,Y1) will have X1 = 0 and Y1 can be calculated via Y1 = m'x + y3. The point (X2,Y2) will have Y2 = 0 and X2 = (y - Y2)/m' + x3.
How can I find the angle between two points of a circle?
From the MSDN documentation page for Atan2, it returns a result between -180 and 180 degrees (-pi to pi radians). On the other hand, you require 0 to 360. To do this, simply add 360 to the final answer in degrees if it is negative.
radian = Math.Atan2(y1 - Cy, x1 - Cx);
angle = radian * (180 / Math.PI);
if (angle < 0.0)
angle += 360.0;
Related Topics
Learning Single Responsibility Principle with C#
How to Create a C# App That Decides Itself Whether to Show as a Console or Windowed App
Conditionally Required Property Using Data Annotations
How Can a Wpf Usercontrol Inherit a Wpf Usercontrol
Add a Package with a Local Package File in 'Dotnet'
Give Some Command to View in Mvvm
Post-Increment Within a Self-Assignment
Why Re-Initiate the Dbcontext When Using the Entity Framework
Remove the Title Bar in Windows Forms
How to Write Super-Fast File-Streaming Code in C#
Sqlite Keeps the Database Locked Even After the Connection Is Closed
Build Visual Studio Project Through the Command Line
Multi Processes Read&Write One File