I'm in a situation that I have a point Vector3(x,y,z), and I need from that starting point to generate a circle in 3D (a ring) that starts with that point and ends with it. Right now I can generate a circle of vector3, but I don't know how to generate it using just one point. For example the main point is Red, and others are points are in black:
-
why negation without saying a reason ? – ragia Mar 12 '15 at 09:45
-
Related: [How do I calculate a point on a circle’s circumference?](http://stackoverflow.com/questions/839899/how-do-i-calculate-a-point-on-a-circle-s-circumference) – Sayse Mar 12 '15 at 09:45
-
You need at least three points to define a circle – Niklas B. Mar 12 '15 at 09:48
-
@Sayse I'm having one point and I want to continue make a circle from that point. – ragia Mar 12 '15 at 09:52
3 Answers
To define a circle, whether it's in a 2D or a 3D space, you need three separate points that lie on the circle.
Otherwise, there are countless (mathematically infinite) possibilities.
If you only have one point, where on the circle (top, bottom, ...) is it located? What is the radius of the circle? Given that it's a 3D space, what is its inclination? You can't derive that from a single (x,y,z,) point.
Edit I made a small visualization in Paint. Note that this is a 2D plane, but the same applies to a 3D space (the three points just need to be coplanar, which any set of three points by definition are)
Edit 2
This type of question may have been better to ask on a geometry or game development (as I suspect that's what you're doing) related StackExchange site, since the question is really a geometrical issue, not a coding one.
Edit 3
I'm not going to write the code for you, as "please write my code" isn't the intention of StackOverflow.
However, there are resources online that will help with the algebraic derication of a circle, you just need to put it in code.
According to this earlier answer on SO, you can find a very detailed explanation of circle-related formulae on this reference page. Look for "Equation of a Circle from 3 Points (2 dimensions)".
Edit 4, final edit
As you asked, you can define a circle based on two points if one of those points is the center point of the circle.
The radius of the circle can then be calculated from the distance between those two points.
From then on, if you have the center point and circle radius, you can calculate any point on the circle. Please refer to the same reference link I mentioned above, as this page contains a lot of ways to derive circles from different sent of data.
Edit 5, really the final edit this time :)
This StackOverflow answer explains what you want to do in code. It assumes you know the center point and the radius, which you can derive as I mentioned above.
I hope this is enough information to help you further :)
-
the radius is constant that I can modify, and in it will be only in XZ plane – ragia Mar 12 '15 at 09:52
-
is it possible If I have another one point, that should be the center of the generated circle besides the giving point(red point) – ragia Mar 12 '15 at 09:54
-
You need three points. I just made a small demo in Paint to explain, uploading it now... – Flater Mar 12 '15 at 09:55
-
This site is not intended for "please write my code" type questions. I will now update my question with useful links that will help with setting up the derivation of the circle, give me a minute. – Flater Mar 12 '15 at 10:00
-
I mean suppose in the green circle. I have one point and the center, can I start from that ? – ragia Mar 12 '15 at 10:01
-
but is it possible to derive the circle from one center point and another point on the circumference ? – ragia Mar 12 '15 at 10:03
-
Yes, for a center point and one point on the circle, you can do this. I'll update my answer with a basic description of how to define it (it will link back to the same reference URL) – Flater Mar 12 '15 at 10:04
Heres an example of how to calculate circle points with a given center vector and a radius.
This is for a plane, but you could rotate them using another rotation-matrix.
class Program
{
static void Main(string[] args)
{
int n = 22; //the number of points
float radius = 22f;
Vector3 vector = new Vector3(radius, 0, 0); //the vector you keep rotating
Vector3 center = new Vector3(33,33,33); //center of the circle
float angle = (float)Math.PI * 2 / (float)n;
Vector3[] points = new Vector3[n];
Matrix rotation = Matrix.RotationZ(angle);
for (int i = 0; i < n; i++)
{
points[i] = vector + center;
vector.TransformNormal(rotation);
}
}
}
I used the managed directX framework for the project ... not sure what you use
Edit
Schematic about the rotation and translation problem:

- 4,682
- 2
- 16
- 28
-
Servus :), I have updated my code, but still its not working. the circle is shifted a lot away from the center. I'm using unity. – ragia Mar 12 '15 at 10:11
-
@ahmedragia ??? all you need to do is calculate the center and the rotation from the startingpoint to a plane... create a matrix from it and do points[i] = (vector + center).TransformNormal(theRotationMatrix) and you should be there – Florian Schmidinger Mar 12 '15 at 10:15
-
I have updated the picture, I have a cube which should be the center, and a camera object which should be a point on the circle. I have done your calculations, but that's the result that I get. and that's very weird – ragia Mar 12 '15 at 10:17
-
@ahmedragia err: points[i] = vector.TransformNormal(TheRotationMatrix) + center... first rotate then translate – Florian Schmidinger Mar 12 '15 at 10:18
-
-
-
@ahmedragia yeah i made the mistake myself... you can figure out how a vector behaves if you get that the center of the rotation (unless you do it with a different method) is always the center 0,0,0 – Florian Schmidinger Mar 12 '15 at 10:22
-
You think of a vector if it is a stick... when you rotate you rotate the tip of the stick around the origin. if you translate first you do the same thing ... with the tip of the stick though so you actually have another stick (smaller or bigger) and do the same thing... different outcome – Florian Schmidinger Mar 12 '15 at 10:26
-
@ahmedragia The tail of the stick stays in the center and the length of the stick is constant – Florian Schmidinger Mar 12 '15 at 10:29
C# using GeoDesy and NetTopologySuite.
static Geometry Circle(double lat, double lon, double meters)
{
GeodeticCalculator geoCalc = new GeodeticCalculator(Ellipsoid.WGS84);
GlobalCoordinates start = new GlobalCoordinates(new Angle(lat), new Angle(lon));
int sides = 4;
int degree_unit = 360 / sides;
var c = new List<NetTopologySuite.Geometries.Coordinate>();
for (int i = 0; i < sides; i++)
{
GlobalCoordinates dest = geoCalc.CalculateEndingGlobalCoordinates(start, new Angle(degree_unit * i), meters);
c.Add(new NetTopologySuite.Geometries.Coordinate(dest.Longitude.Degrees, dest.Latitude.Degrees));
}
c.Add(c[0]);
GeometryFactory gc = new GeometryFactory(new PrecisionModel(), 4326);
var box = gc.CreatePolygon(c.ToArray());
var mbc = new MinimumBoundingCircle(box);
return mbc.GetCircle();
}