Curve shape filling

Programming, for all ages and all languages.
Post Reply
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Curve shape filling

Post by blackoil »

Hi,

Does anyone know how to do curve shaped scanline filling?

I am stucked in fp coordinary intersection.
When rounding fp to int, several intersection points might appear.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Curve shape filling

Post by Solar »

(OT: /me never ceases to wonder: No matter how much you know, as soon as someone talks about an area of expertise you haven't touched yet, it sounds like {technobabble} all over again just like the first day...)
Every good solution is obvious once you've found it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Curve shape filling

Post by Combuster »

A scanline is always straight, i.e. not a curve.

Context please?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: Curve shape filling

Post by blackoil »

similar to polygon fill, but polygon edge is line, only one scanline intersection point per edge.

A quadratic curve may have 1 or 2 intersection point per scanline filling, and its coordinate is floating point. When rounding to integer, it produces 2+ integer intersection point, that makes scanline filling hard to work.

Assume to fill a half moon pattern on screen, which pixels to spot?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Curve shape filling

Post by Combuster »

A quadratic polynomial curve has atmost two intersections with any line, and atmost two maxima with any plane intersection. Yes, those locations are floats, but conversion from float to integer only yields one and only one integer per float (which does differ based on the rounding used, but you use a fixed one for each edge, so each float maps to exactly one integer)

In addition, I have a raytracer which renders implicit quadratics with the help of scanline rendering, and from experience I only get atmost two float intersections, and thus atmost two integer intersections.

So I still fail to see the problem.

Regarding the half-moon object - it isn't a pure quadratic, it is a composition of two quadratic surfaces like you do constructive solid geometry. That means that for the total object, you get four intersections (atmost two for each base object), and you demand a certain property of the overlapping area, usually one of: both (intersection), either (union), or one but not the other (subtraction). The surface is then defined for each of the 5 segments between the points, and you get the answer by checking each segment of the scanline for the desired property.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: Curve shape filling

Post by blackoil »

hi, combuster,

how to make only one intersection point, when comparing to two floating point values.
it's rare that two floating point are the same exactly.

I set quadratic curve coefficent T, stepping in 0.01,
then I got points like [10.3 , 10.2], [11.1 , 10.4],
after rounding to integer, I got [10 , 10], [11 , 10]

so I got 2 adjacent intersection, that fails my scanline renderer.

Code: Select all

void	QuadraticCurve(FPOINT* path,FPOINT* start,FPOINT* control,FPOINT* end,float t)
{
	(*path).x=(1.0-t)*(1.0-t)*(*start).x + 2.0*(1.0-t)*t*(*control).x + t*t*(*end).x;
	(*path).y=(1.0-t)*(1.0-t)*(*start).y + 2.0*(1.0-t)*t*(*control).y + t*t*(*end).y;
}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Curve shape filling

Post by Combuster »

scanlines share a (Y-)coordinate. You are trying to render a diagonal line as a horizontal line (which obviously does not work).

for scanline conversion:

y = ax²+bx+c
solve x coordinates for each y

x = b+V(b²-4ac) / 2a
and
x = b-V(b²-4ac) / 2a

which yields (x1, y) and (x2, y) as intersections.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: Curve shape filling

Post by blackoil »

I forget their math connection for a long time.

Code: Select all

void	QuadraticCurve(FPOINT* path,FPOINT* start,FPOINT* control,FPOINT* end,float t)
{
	(*path).x=(1.0-t)*(1.0-t)*(*start).x + 2.0*(1.0-t)*t*(*control).x + t*t*(*end).x;
	(*path).y=(1.0-t)*(1.0-t)*(*start).y + 2.0*(1.0-t)*t*(*control).y + t*t*(*end).y;
}
y = ax²+bx+c

could you please give me the detailed code?
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: Curve shape filling

Post by blackoil »

and it looks like the curve could be rotated, to form the shape.

I am not good at math, but I have the feeling.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Curve shape filling

Post by Combuster »

blackoil wrote:could you please give me the detailed code?
Not going to do your homework.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Curve shape filling

Post by Brendan »

Hi,
blackoil wrote:and it looks like the curve could be rotated, to form the shape.
I get the feeling you're going about it the wrong way to begin with. Any curves get converted into vertexes and lines during pre-processing, and the rendering code never sees any curves (it just rotates/scales/translates vertexes, and follows lines between vertexes).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: Curve shape filling

Post by blackoil »

I checked wikipedia, the curve I mentioned before was Quadratic Bezier Curve, not Quadratic Equation. If found good way to get valid intersections, it's not difficult to fill its area, even for higher degree curve.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Curve shape filling

Post by gravaera »

Combuster wrote:A quadratic polynomial curve has atmost two intersections with any line, and atmost two maxima with any plane intersection. Yes, those locations are floats, but conversion from float to integer only yields one and only one integer per float (which does differ based on the rounding used, but you use a fixed one for each edge, so each float maps to exactly one integer)

In addition, I have a raytracer which renders implicit quadratics with the help of scanline rendering, and from experience I only get atmost two float intersections, and thus atmost two integer intersections.

So I still fail to see the problem.

Regarding the half-moon object - it isn't a pure quadratic, it is a composition of two quadratic surfaces like you do constructive solid geometry. That means that for the total object, you get four intersections (atmost two for each base object), and you demand a certain property of the overlapping area, usually one of: both (intersection), either (union), or one but not the other (subtraction). The surface is then defined for each of the 5 segments between the points, and you get the answer by checking each segment of the scanline for the desired property.
Wow...amazing. :shock:

*Visits Combuster's profile page, and bookmarks it. Begins drafting out how much $$ I'll offer Combuster to join my dev team when the time comes.*

Oh...and *makes threatening face at all other forum members to back off.* :twisted:
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Post Reply