How to move point on arc?

Posted by bbZ on Stack Overflow See other posts from Stack Overflow or by bbZ
Published on 2014-05-30T18:44:23Z Indexed on 2014/05/30 21:27 UTC
Read the original article Hit count: 251

Filed under:
|

I am writing an app that is simulating RobotArm movement. What I want to achieve, and where I have couple of problems is moving a Point on arc (180degree) that is arm range of movement. I am moving an arm by grabbing with mouse end of arm (Elbow, the Point I was talking about), robot can have multiple arms with diffrent arm lenghts.

If u can help me with this part, I'd be grateful.

This is what I have so far, drawing function:

public void draw(Graphics graph) { 
    Graphics2D g2d = (Graphics2D) graph.create();

    graph.setColor(color);
    graph.fillOval(location.x - 4, location.y - 4, point.width, point.height); //Draws elbow
    if (parentLocation != null) {
        graph.setColor(Color.black);
        graph.drawLine(location.x, location.y, parentLocation.x, parentLocation.y); //Connects to parent

        if (arc == null) {
            angle = new Double(90 - getAngle(parentInitLocation));
            arc = new Arc2D.Double(parentLocation.x - (parentDistance * 2 / 2), parentLocation.y - (parentDistance * 2 / 2), parentDistance * 2, parentDistance * 2,
                    90 - getAngle(parentInitLocation), 180, Arc2D.OPEN); //Draws an arc if not drawed yet.
        }
        else if (angle != null) //if parent is moved, angle is moved also
        {
            arc = new Arc2D.Double(parentLocation.x - (parentDistance * 2 / 2), parentLocation.y - (parentDistance * 2 / 2), parentDistance * 2, parentDistance * 2,
                    angle, 180, Arc2D.OPEN);
        }
        g2d.draw(arc);
    }
    if (spacePanel.getElbows().size() > level + 1) {//updates all childElbows position
        updateChild(graph);
    }
}

I just do not know how to prevent moving Point moving outside of arc line. It can not be inside or outside arc, just on it.

Here I wanted to put a screenshot, sadly I don't have enough rep. Am I allowed to put link to this?

Maybe you got other ways how to achieve this kind of thing.

Here is the image:
enter image description here

Red circle is actual state, and green one is what I want to do.

EDIT2: As requested, repo link: https://github.com/dspoko/RobotArm

© Stack Overflow or respective owner

Related posts about java

Related posts about awt