Arc drawing routine

The Partridge Family were neither partridges nor a family. Discuss.
Jezierro
Posts: 36
Joined: March 11th, 2018, 6:02 pm

Re: Arc drawing routine

Post by Jezierro » March 23rd, 2019, 11:23 pm

How about a single algorithm for thick/thin and dotted/normal line drawing algorithm

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Arc drawing routine

Post by albinopapa » March 24th, 2019, 3:54 am

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

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Arc drawing routine

Post by albinopapa » March 24th, 2019, 4:21 am

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.
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

Jezierro
Posts: 36
Joined: March 11th, 2018, 6:02 pm

Re: Arc drawing routine

Post by Jezierro » March 24th, 2019, 10:54 am

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
Przechwytywanie.JPG
(35.38 KiB) Not downloaded yet
and I would like to create a grid

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Arc drawing routine

Post by albinopapa » March 26th, 2019, 10:54 am

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

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Arc drawing routine

Post by chili » March 26th, 2019, 3:23 pm

hmmm, seems like a problem :D
I'll take a look into it
Chili

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Arc drawing routine

Post by chili » March 26th, 2019, 3:51 pm

Server permissions got a little fucked. Should be all good now.
Chili

Jezierro
Posts: 36
Joined: March 11th, 2018, 6:02 pm

Re: Arc drawing routine

Post by Jezierro » March 28th, 2019, 5:06 pm

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

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Arc drawing routine

Post by albinopapa » March 29th, 2019, 8:05 am

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:

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;
	}
}
I tend to like this version more than the formula I found online:

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 );
To clear things up, there are two ways that I know of for linear interpolation:

Code: Select all

// Option 1
value = ( (1-t) * a ) + ( t * b );
// Option 2
value = a + ( ( b - a ) ) * t;
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.
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

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Arc drawing routine

Post by albinopapa » March 30th, 2019, 4:50 am

Your dot_product() function has a but in it btw.

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 );
}
Found it while testing some code.
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

Post Reply