Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

c - find the length of any arc on a circle - confrim limits are on the required arc

This question follows on from find the length of any arc on a circle

From that question:

I have a magnetic encoder that returns the position of the shaft from 0 to 4095.

The servo has two logical end points, call them MAX and MIN which are set in software and can be changed at any time, and the shaft must rotate (i.e. travel) on one arc between the MAX and MIN positions. For example in the picture the blue arc is valid but the red is not for all travel between and including MIN and MAX.

I am trying to work out a simple algorithm to validate that where travel is allowed on the BLUE side of my circle, that A and B are on the BLUE arc and neither are on the RED arc, and the opposite where if the allowed arc of travel is RED, then A and B are both on the RED arc?

Top view of the servo shaft

Note: A and B are set by the calling program and are always changing.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I am going to restate the problem this way: Given the positions MIN, MAX and SHAFT, determine if both A and B are on the same arc that contains SHAFT.

The following code will determine if point x lies on the same arc defined by MIN, MAX and SHAFT. The assertions spell out the preconditions.

    assert(shaft != min);
    assert(shaft != max);
    assert(min < max);

    if (min < shaft && shaft < max) {
        return min < x && x < max;
    }

    return x < min || x > max;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...