I have a triangle drawn by a user and all the points are stored in a n array. Then I want to draw a “correct” triangle with straight lines from these data. Can anyone point me in the right direction. An alternative could be to force the user to draw the triangle in three seperate line and just use the start and end point of each line to draw the triangle – but I would prefer to avoid this approach.
All help is appreciated
Regards
Bjarke,
As far as drawing your triangle it’s rather simple. You can use UIBezierPaths or CGPaths to accomplish the drawing:
As far as figuring out which points are your vertices this is a little more complicated and very math related. Two things that may help with this are:
1) The slope of the line will change once a vertex is hit. So you can check each point against the previous point and if the slope (delta x / delta y) is different (within reason as the original triangle is hand drawn) than the previous slope a vertex has most likely been reached.
2) The vertices are (in MOST cases) the extremities of your triangle (min/max x and y). However there are situations where this is not the case making this far less reliable.
Cheers.