Arc drawing routine
Re: Arc drawing routine
How about a single algorithm for thick/thin and dotted/normal line drawing algorithm
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Arc drawing routine
Just lines? or outlines of any shape?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Arc drawing routine
For thickness of the circle, just pass in a variable to change the inner radius.
For line thickness and to avoid "holes" due to rounding errors, you'd probably actually want to make lines from rasterized polygons.
For polylines, you'd then want to calculate the normals of each connecting line so the obtuse angles don't leave holes.
Chili covers polyline thickness drawing using rasterized polygons in the old Advance series, episode 9.
You'll need to be able to software render triangles which is also covered in that video.
If you're feeling lazy lol, I'll have something up in about a day or maybe in a few hours, depends on how things go.
I'd like to implement this for a project as well.
You could also use the 3D Fundamentals framework as a starting point.
For line thickness and to avoid "holes" due to rounding errors, you'd probably actually want to make lines from rasterized polygons.
For polylines, you'd then want to calculate the normals of each connecting line so the obtuse angles don't leave holes.
Chili covers polyline thickness drawing using rasterized polygons in the old Advance series, episode 9.
You'll need to be able to software render triangles which is also covered in that video.
If you're feeling lazy lol, I'll have something up in about a day or maybe in a few hours, depends on how things go.
I'd like to implement this for a project as well.
You could also use the 3D Fundamentals framework as a starting point.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Arc drawing routine
Have look at my books collection
https://drive.google.com/drive/folders/ ... sp=sharing
Some of them may be helpful
In the beginning, I would like to implement a line segment with the ability to be drawn as a dashed or dotted line to trace bezier control points
and I would like to create a grid
https://drive.google.com/drive/folders/ ... sp=sharing
Some of them may be helpful
In the beginning, I would like to implement a line segment with the ability to be drawn as a dashed or dotted line to trace bezier control points
and I would like to create a grid
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Arc drawing routine
Sorry to hijack this thread, but is anyone else having troubles creating a new thread? I keep getting error 500, so the only way I can post something is responding to a thread already created. This has been happening over the past day or two for me.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Arc drawing routine
I am having problems with the closest point calculation formula for line
for some slopes, it is not calculated
Could you have a look
Btw
thanx to you I know how to implement proper bezier class formula
for some slopes, it is not calculated
Could you have a look
Btw
thanx to you I know how to implement proper bezier class formula
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Arc drawing routine
Haven't looked at the line stuff yet, but I thought I'd give a crack at the four point bezier curve, and instead of recursively interpolating between the four points, I widdled away at the variables until I came up with this:
I tend to like this version more than the formula I found online:
To clear things up, there are two ways that I know of for linear interpolation:
I used Option 2 to find the formula I used. I believe Option 1 is used for the formula found online.
The reason I like my way is it allows for so many more precalculations outside the loop, whereas the other version all has to be done inside the loop without any precalculations.
Code: Select all
void Graphics::DrawQuadraticBezier( const JC_Point2d & p0, const JC_Point2d & p1, const JC_Point2d & p2, const JC_Point2d & p3, Color color ) noexcept
{
const auto range10 = p1 - p0;
const auto range21 = p2 - p1;
const auto range32 = p3 - p2;
//( ( p2 - p1 ) - ( p1 - p0 ) )
const auto range2110 = range21 - range10;
//( ( p3 - p2 ) - ( p2 - p1 ) )
const auto range3221 = range32 - range21;
//( p1 - p0 ) * 3.f
const auto range10x3 = range10 * 3.;
//( ( p2 - p1 ) - ( p1 - p0 ) ) * 3.f
const auto range2110x3 = range2110 * 3.;
//( ( p3 - p2 ) - ( p2 - p1 ) ) - ( ( p2 - p1 ) - ( p1 - p0 ) )
const auto range3221_2110 = range3221 - range2110;
auto prev = JC_Point2i( p0 );
for( int i = 0; i <= 10; ++i )
{
const auto t = static_cast< double >( i ) * 0.1;
const auto t2 = Square( t );
const auto t3 = Square( t ) * t;
const auto cur =
JC_Point2i( p0 + ( range10x3 * t ) + ( range2110x3 * t2 ) + ( range3221_2110 * t3 ) );
DrawLine( prev.x, prev.y, cur.x, cur.y, color );
prev = cur;
}
}
Code: Select all
const auto it = 1 - t;
const auto itSq = Square( it );
const auto itCu = itSq * it;
const auto tSq = Square( t );
const auto tCu = tSq * t;
( p0 * itCu ) + ( ( p1 * itSq * t * 3 ) ) + ( p2 * it * tSq * 3 ) + ( p3 * tCu );
Code: Select all
// Option 1
value = ( (1-t) * a ) + ( t * b );
// Option 2
value = a + ( ( b - a ) ) * t;
The reason I like my way is it allows for so many more precalculations outside the loop, whereas the other version all has to be done inside the loop without any precalculations.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Arc drawing routine
Your dot_product() function has a but in it btw.
Found it while testing some code.
Code: Select all
template<typename T> T dot_product( const JC_Vector2<T>& v0, const JC_Vector2<T>& v1 )
{
return ( v0.x * v1.x ) + ( v0.y + v1.y );
}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com