# How to determine the axis of a prolonged object?

The angle of the line is of primary interest. I know an algorithm for ellipse (will post it here as answer later), but would like to find out what is popular for an arbitrary shape. Fast methods are preferable for work with video input.

edit retag close merge delete

1
( 2019-01-08 02:26:19 -0500 )edit

Yes, this is classics. It is based on the method of least squares. Only I guess it will be not very fast? By the way, do you know how modern math processors work? In the past, floating point arithmetic was substantially slower than integer numbers. Now I tested and the speed is the same.

( 2019-01-08 04:39:08 -0500 )edit

I'm sorry... are you looking for the line and the angle, or just the angle?

( 2019-01-08 10:50:52 -0500 )edit

Sort by ยป oldest newest most voted

If you have the end points of the line, then getting the angle is pretty straightforward:

#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
float x0 = 0.0f;
float y0 = 0.0f;

float x1 = 1.0f;
float y1 = 1.0f;

float rise = y1 - y0;
float run  = x1 - x0;

float pi = 4.0f*atanf(1.0f);

float slope = rise/run;

float angle_radians = atanf(slope);
float angle_degrees = angle_radians/pi*180.0f;

cout << rise << endl;
cout << run << endl;
cout << angle_radians << endl;
cout << angle_degrees << endl;

return 0;
}

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2019-01-08 02:13:45 -0500

Seen: 57 times

Last updated: Jan 09