Sign in to follow this  
sv161

CD for ellipsoids

Recommended Posts

Evil Steve    2017

Get vectors to the two corners of the triangle from one other point:
v0 = pt1 - pt0;
v1 = pt2 - pt0;

// Get the normal:
n = crossProduct(v1, v0);
normalise(n);

// Get d:
d = -dotProduct(n, pt0);

Share this post


Link to post
Share on other sites
sv161    122
Something's still wrong. ClsPt determines fine, but ClsPtPl is wrong.
	float d=-n.dot(v1);
float
dispN=disp.dot(n),
ElCtrDisp=c.dot(n)+d;
//Skip early out test to be able to visualize all data
//if(ElCtrDisp-1>dispN)
// return false;

//Using article "Appendix A"
float
k=-2*1/pow((n.Coords[0]*n.Coords[0]*sx*sx+
n.Coords[1]*n.Coords[1]*sy*sy+
n.Coords[2]*n.Coords[2]*sz*sz),0.5);
c_Vector3 ClsPt(k*n.Coords[0]*sx*sx/2.0,
k*n.Coords[1]*sy*sy/2.0,
k*n.Coords[2]*sz*sz/2.0);

glPushMatrix();
glTranslatef(c.Coords[0],c.Coords[1],c.Coords[2]);
glScalef(sx,sy,sz);
float amb[4]={0.1,0.1,0.1,1},dif[4]={0,1,0,1};
glEnable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,amb);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,dif);
glutWireSphere(1,20,20);
glPopMatrix();
amb[0]=1;amb[1]=0;amb[2]=0;amb[3]=1;
dif[0]=0;dif[1]=1;dif[2]=0;dif[3]=1;
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,amb);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,dif);
glBegin(GL_TRIANGLES);
glNormal3fv(n.Coords);
glVertex3fv(v1.Coords);
glVertex3fv(v2.Coords);
glVertex3fv(v3.Coords);
glEnd();
glDisable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glBegin(GL_POINTS);
glVertex3fv((c+ClsPt).Coords);
glVertex3fv(c.Coords);
glEnd();
glBegin(GL_LINES);
glVertex3fv((c+ClsPt).Coords);
glVertex3fv(c.Coords);
glVertex3fv((v1+n).Coords);
glVertex3fv(v1.Coords);
glEnd();
glEnable(GL_LIGHTING);

float
elSep=ClsPt.dot(n)+d,
t=elSep/dispN;
//Skip early out test to be able to visualize all data
//if(t>1)
// return false;
c_Vector3 ClsPtPl=ClsPt-n*elSep;

glBegin(GL_POINTS);
glVertex3fv((c+ClsPtPl).Coords);
glEnd();
glBegin(GL_LINES);
glVertex3fv((c+ClsPtPl).Coords);
glVertex3fv((c+ClsPt).Coords);
glEnd();
...

Here is image what i got:
CD

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this