3
\$\begingroup\$

I am trying to implement Dual Contouring, following serveral sources, mainly http://www.sandboxie.com/misc/isosurf/isosurfaces.html but now I want to implement finding the feature point as explained in this post https://gamedev.stackexchange.com/a/83757/49583

It begins with

The QEF you are minimizing is simply the total distance to each of the planes that are defined by the intersection point/normal pairs for that cell.

I do have the intersection point, which is just the edge vertices averaged by their densities. I got the normal by averaging the normal of the edge vertices. I do it like this :

        //calculate normals by gradient of surface, d(x,y,z) = density function, d0 = density at p0, d1 = density at p1
        Vector3 n0 = new Vector3(d((int)(p0.x+1),   (int)p0.y,      (int)p0.z       ).Value - d0,
                                 d((int)p0.x,       (int)(p0.y+1),  (int)p0.z       ).Value - d0,
                                 d((int)p0.x,       (int)p0.y,      (int)(p0.z+1)   ).Value - d0);
        Vector3 n1 = new Vector3(d((int)(p1.x+1),   (int)p1.y,      (int)p1.z       ).Value - d1,
                                 d((int)p1.x,       (int)(p1.y+1),  (int)p1.z       ).Value - d1,
                                 d((int)p1.x,       (int)p1.y,      (int)(p1.z+1)   ).Value - d1);

        this.normal = Vector3.Lerp(n0,n1,m);

My plane is this :

Vector4 plane = new Vector4(edge.normal.x, edge.normal.y, edge.normal.z, Vector3.Dot(edge.point, edge.normal));

And I have a vertex at (x,y,z),

Basically, you start the vertex in the centre of the cell. Then you average all the vectors taken from the vertex to each plane and move the vertex along that resultant...

How do I get the vector from the plane to the vertex?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

First of all, your plane representation is wrong. It should be

Vector4 plane = new Vector4(edge.normal.x, edge.normal.y, edge.normal.z, -Vector3.Dot(edge.point, edge.normal));

since the general representation for a plane is ax + by + cz + d = 0.

To get a vector from the plane to the vertex, you'll first have to find the perpendicular signed distance from the plane to the vertex and multiply it by the normal. The formula for this is n.AB where n is the normal of the plane and A is a point on the plane and B is the input point. Using the above representation of a plane, this formula becomes n.B + d. So in this case the signed distance will be

float distance = Vector3.Dot(edge.normal, vertex) + plane.w;

To get the vector from the plane to the vertex, just multiply the signed distance by the normal:

Vector3 planeToVertex = edge.normal * distance;

With this formula, the resulting vector will point in the direction of the normal if the point is above the plane and opposite the normal if the point is below the plane.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .