A
A
alienstone2016-05-09 10:11:00
Programming
alienstone, 2016-05-09 10:11:00

How to draw only part of a circle given by bezier curve points?

Good afternoon
I have the following task:
There are points that define a square Bezier curve: p0, p2 - main, p1 - auxiliary.
I need to draw a circle using these points. We assume that the segment drawn through p0 and p2 divides the circle exactly in half. And what part of the circle to choose for drawing, we determine on which side of this segment the auxiliary point p1 lies.
I've searched everything I could and came up with this:

Vec2f O( 0, 0 );
        Vec2f P0( p0->getX(), p0->getY());
        Vec2f P2( p2->getX(), p2->getY());

        if ( O.distance( P2 ) < O.distance( P0 ) ) std::swap( P0, P2 );

        double angle1 = std::atan2( C.y - P0.y, C.x - P0.x );
        double angle2 = std::atan2( C.y - P2.y, C.x - P2.x );

        for ( double t = angle2; t >= angle1; t -= 0.1 ) {
            int x = R*cos(t);
            int y = R*sin(t);
            Point::drawPoint( image, x+minx, y+miny, qRgb( 255, 0, 0 ));
        }

But nothing is drawn. Help me please!
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2016-05-09
@Rsa97

1. If the segment P 0 P 2 divides the circle in half, then the center of the circle lies on this segment.
2. The radius of the circle is not clear from the condition. If it must pass through the points P 0 and P 2 , then the center of the circle lies in the middle of the segment.
3. Since the segment divides the circle in half, then the arc will start from the angle of the vector P 2 P 0 and end at ±π from this angle. The direction of rotation is determined by the position of the point P 1 relative to the vector P 2 P 0 .

A
Alexander Ruchkin, 2016-05-09
@VoidEx

A well-formulated question is half the answer.
What does "nothing is drawn" mean? There are no dots?
Then check if the dot is just drawn somewhere. If not, look for why.
In addition, it is better to draw a curve from small segments, and not from points. Those. it is necessary to consider the "previous point" and "current point", draw (draw) a segment; then jump to a new point, keeping "current" to "previous", and so on.
Try to draw segments P0-P1, P1-P2 in order to generally evaluate the bezier anchor points in the picture, and then do some calculations, maybe the problem is in the calculations.
Well, and so on, then it will be seen what the problem is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question