简体   繁体   中英

How to walk along a Java shape and translate it to left/right/straight commands?

I have Java Shape objects. If I follow the line for example pixel by pixel it would translate to a sequence of straight, straight, ... commands. If I follow a circle, I would be something like left, straight, left, straight, ... How can I solve this with Java?

I would get a pathIterator from the shape,

public PathIterator getPathIterator(AffineTransform at)

and from the iterator, call

int currentSegment(double[] coords) 

then given the starting and ending pt, you can calculate the slope of the line.

At any segment along the way, if you have the slop of the previous line seqment, and the slope of the current line segment, you can tell in what relative direction to go using the dot product to determine the angle.

我可能会选择一个起始像素,将其存储在一个数组中,然后查找不在该数组中的周围像素,存储到达那里的方向,等等。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM