Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9013839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:22:03+00:00 2026-06-16T03:22:03+00:00

We have 3(three) xyz points that define a circle in 3D space, this circle

  • 0

We have 3(three) xyz points that define a circle in 3D space, this circle needs to be converted into a polyline(for further rendering). I’m looking for a ready C or C++ function or free library that can do the job.

Don’t understand why this was closed. And I can’t even answer my own question there. Shame on you guys. But you will not stop the knowledge spreading!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:22:04+00:00Added an answer on June 16, 2026 at 3:22 am

    There is a nice article and a code sample on how to build a circle by 3 points in 2D, XY plane.

    http://paulbourke.net/geometry/circlesphere/

    http://paulbourke.net/geometry/circlesphere/Circle.cpp

    To build a 3D circle we’ll have to:

    • rotate our 3 points into XY plane
    • Calculate circle center
    • build a circle in XY plane using the code in the article
    • rotate it back into it’s original plane

    For rotations it is best to use quaternions.

    To find a correct quaternion I looked at Ogre3d source code:
    void Quaternion::FromAngleAxis (const Radian& rfAngle, const Vector3& rkAxis)

    There is one more useful function there:
    Quaternion getRotationTo(const Vector3& dest, const Vector3& fallbackAxis = Vector3::ZERO) const
    But I didn’t use it.

    For quaterions and vectors I used our own classes. Here is the full source code of the function that does the job:

    bool IsPerpendicular(Point3d *pt1, Point3d *pt2, Point3d *pt3);
    double CalcCircleCenter(Point3d *pt1, Point3d *pt2, Point3d *pt3, Point3d *center);
    
    void FindCircleCenter(const Point3d *V1, const Point3d *V2, const Point3d *V3, Point3d *center)
    {
        Point3d *pt1=new Point3d(*V1);
        Point3d *pt2=new Point3d(*V2);
        Point3d *pt3=new Point3d(*V3);
    
    
        if (!IsPerpendicular(pt1, pt2, pt3) )       CalcCircleCenter(pt1, pt2, pt3, center);
        else if (!IsPerpendicular(pt1, pt3, pt2) )  CalcCircleCenter(pt1, pt3, pt2, center);
        else if (!IsPerpendicular(pt2, pt1, pt3) )  CalcCircleCenter(pt2, pt1, pt3, center);
        else if (!IsPerpendicular(pt2, pt3, pt1) )  CalcCircleCenter(pt2, pt3, pt1, center);
        else if (!IsPerpendicular(pt3, pt2, pt1) )  CalcCircleCenter(pt3, pt2, pt1, center);
        else if (!IsPerpendicular(pt3, pt1, pt2) )  CalcCircleCenter(pt3, pt1, pt2, center);
        else {
            delete pt1;
            delete pt2;
            delete pt3;
            return;
        }
        delete pt1;
        delete pt2;
        delete pt3;
    
    }
    
    bool IsPerpendicular(Point3d *pt1, Point3d *pt2, Point3d *pt3)
    // Check the given point are perpendicular to x or y axis
    {
        double yDelta_a= pt2->y - pt1->y;
        double xDelta_a= pt2->x - pt1->x;
        double yDelta_b= pt3->y - pt2->y;
        double xDelta_b= pt3->x - pt2->x;
    
        // checking whether the line of the two pts are vertical
        if (fabs(xDelta_a) <= 0.000000001 && fabs(yDelta_b) <= 0.000000001){
            return false;
        }
    
        if (fabs(yDelta_a) <= 0.0000001){
            return true;
        }
        else if (fabs(yDelta_b) <= 0.0000001){
            return true;
        }
        else if (fabs(xDelta_a)<= 0.000000001){
            return true;
        }
        else if (fabs(xDelta_b)<= 0.000000001){
            return true;
        }
        else
            return false ;
    }
    
    double CalcCircleCenter(Point3d *pt1, Point3d *pt2, Point3d *pt3, Point3d *center)
    {
        double yDelta_a = pt2->y - pt1->y;
        double xDelta_a = pt2->x - pt1->x;
        double yDelta_b = pt3->y - pt2->y;
        double xDelta_b = pt3->x - pt2->x;
    
        if (fabs(xDelta_a) <= 0.000000001 && fabs(yDelta_b) <= 0.000000001){
            center->x= 0.5*(pt2->x + pt3->x);
            center->y= 0.5*(pt1->y + pt2->y);
            center->z= pt1->z;
    
            return 1;
        }
    
        // IsPerpendicular() assure that xDelta(s) are not zero
        double aSlope=yDelta_a/xDelta_a; //
        double bSlope=yDelta_b/xDelta_b;
        if (fabs(aSlope-bSlope) <= 0.000000001){    // checking whether the given points are colinear.
            return -1;
        }
    
        // calc center
        center->x= (aSlope*bSlope*(pt1->y - pt3->y) + bSlope*(pt1->x + pt2 ->x)
                             - aSlope*(pt2->x+pt3->x) )/(2* (bSlope-aSlope) );
        center->y = -1*(center->x - (pt1->x+pt2->x)/2)/aSlope +  (pt1->y+pt2->y)/2;
    
        return 1;
    }
    
    //! Builds a circle in 3D space by 3 points on it and an optional center
    void buildCircleBy3Pt(const float *pt1,
                          const float *pt2,
                          const float *pt3,
                          const float *c,       // center, can be NULL
                          std::vector<float> *circle)
    {
        /*  Get the normal vector to the triangle formed by 3 points
            Calc a rotation quaternion from that normal to the 0,0,1 axis
            Rotate 3 points using quaternion. Points will be in XY plane 
            Build a circle by 3 points on XY plane 
            Rotate a circle back into original plane using quaternion
         */
        Point3d p1(pt1[0], pt1[1], pt1[2]);
        Point3d p2(pt2[0], pt2[1], pt2[2]);
        Point3d p3(pt3[0], pt3[1], pt3[2]);
        Point3d center;
        if (c)
        {
            center.set(c[0], c[1], c[2]);
        }
    
        const Vector3d p2top1 = p1 - p2;
        const Vector3d p2top3 = p3 - p2;
    
        const Vector3d circle_normal = p2top1.crossProduct(p2top3).normalize();
        const Vector3d xy_normal(0, 0, 1);
    
    
        Quaternion rot_quat;
        // building rotation quaternion
        {
            // Rotation axis around which we will rotate our circle into XY plane
            Vector3d rot_axis = xy_normal.crossProduct(circle_normal).normalize();
            const double rot_angle = xy_normal.angleTo(circle_normal); // radians
    
            const double w = cos(rot_angle * 0.5);
            rot_axis *= sin(rot_angle * 0.5);
    
            rot_quat.set(w, rot_axis.x, rot_axis.y, rot_axis.z);
        }
    
        Quaternion rot_back_quat;
        // building backward rotation quaternion, same as prev. but -angle
        {
            const double rot_angle = -(xy_normal.angleTo(circle_normal)); // radians
            const double w_back = cos(rot_angle * 0.5);
            Vector3d rot_back_axis = xy_normal.crossProduct(circle_normal).normalize();
            rot_back_axis *= sin(rot_angle * 0.5);
            rot_back_quat.set(w_back, rot_back_axis.x, rot_back_axis.y, rot_back_axis.z);
        }
    
        rot_quat.rotate(p1);
        rot_quat.rotate(p2);
        rot_quat.rotate(p3);
        rot_quat.rotate(center);
    
        if (!c)
        {
            // calculate 2D center
            FindCircleCenter(&p1, &p2, &p3, &center);
        }
    
        // calc radius
        const double radius = center.distanceTo(p1);
    
        const float DEG2RAD = 3.14159f / 180.0f;
        // build circle
        for (int i = 0; i < 360; ++i)
        {
            float degInRad = i * DEG2RAD;
            Point3d pt(cos(degInRad) * radius + center.x, sin(degInRad) * radius + center.y, 0);
    
            // rotate the point back into original plane 
            rot_back_quat.rotate(pt);
    
            circle->push_back(pt.x);
            circle->push_back(pt.y);
            circle->push_back(pt.z);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have three projects in my sln. (1) xyz.a{Class Lib}{no reference added} (2)
Have three divs in a container that I want to float over a large
I have three divs, within a content div. Container width 70%. Within that I
Say, I have three interfaces: public interface I1 { void XYZ(); } public interface
I have three code. This is the first one in which I get the
I have three sub-domains namely, a.xyz.com, b.xyz.com, c.xyz.com. Now, I have about 20 ajax
I've ran into a design issue; in a project, i have three tables: League,
I have to deserialize JSON strings that I don't have any control over. This
I have three tables like this: Specialisation sid | s_name -------------- 1 | test
I have three classes: xyz/url/core/datastore/ObjectBase.java xyz/url/core/test/hibernate/BaseClass.java xyz/url/core/test/hibernate/ChildClass.java Their code: ObjectBase package xyz.url.core.datastore; import java.util.Date;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.