ccomputational-geometrytetrahedra

How to find the angles of the faces of a scalene tetrahedron given lengths of edges


I'm writing a program in C to determine the apex of a tetrahedron given the given the lengths of all its edges. The tetrahedron has an equilateral base and scalene sides. In order to complete the formula, I need a way of getting the angle between a face and the equilateral base. I know the height of the altitude of one of the faces, and once I can get the angle between a face and the base, I can rotate the height by that angle and get the position of the apex.

I have 0 idea where to begin figuring out the formula for the angle(see theta below), and how to translate it into C.

I know the lengths of the segments in yellow and am trying to find angle B in blue I know the lengths of the segments in yellow and am trying to find angle B in blue

Here's my code so far:

#include <math.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

typedef struct {
  float x;
  float y;
  float z;
} Point;

typedef struct {
  float edgeA, edgeB, edgeC;
  float legA, legB, legC;
  Point vertexBaseA, vertexBaseB, vertexBaseC;
  Point apex;
} scaleneTetrahedron;

Point p(float x,float y) {
    Point pt; pt.x = x; pt.y = y; pt.z =0;return pt;
}

Point pZ(float x, float y, float z) {
      Point pt; pt.x = x; pt.y = y;pt.z =z; return pt;
}

void printPoint(char *identifier, Point p){
  printf("(%s: %f, %f, %f)\n",identifier, p.x,p.y,p.z);
}

void printFloat(float n) {
  printf("%f",n);
}

scaleneTetrahedron sT_Hedron(float lengthsEdges[3],float lengthsLegs[3],Point vertexBases[3]) {
  scaleneTetrahedron h;
  h.edgeA = lengthsEdges[0], h.edgeB = lengthsEdges[2], h.edgeC = lengthsEdges[2];
  h.legA = lengthsLegs[0], h.legB = lengthsLegs[1],h.legC = lengthsLegs[2];
  h.vertexBaseA = vertexBases[0], h.vertexBaseB = vertexBases[1], h.vertexBaseC = vertexBases[2];
  return h;
}

#define rt(n) (sqrt(n))
float SQUARE(float n) {return n*n;}
float PERP(float slope) { return 1/slope * -1;}
float Rad_To_Deg(float angle) {return angle*57.29577951f;}

#define ANGLE_FOR(rangX,rangY)      ( Rad_To_Deg(atan2(rangX,rangY))     )

float DISTANCE(Point v1, Point v2){
  return sqrtf(SQUARE(v1.x-v2.x) + SQUARE(v1.y-v2.y));

}

float WIDTH(float leg1,float leg2,float base){
  float ret = ((SQUARE(leg1) - SQUARE(leg2)) + SQUARE(base)) / (2 * base);
  printf("Ret is:%f\n",ret);
  return ret;
}

float HEIGHT(float width,float leg1){
  float ret = sqrtf(SQUARE(leg1) - SQUARE(width));
  return ret;
}

float slopeFor(Point A, Point B) {
  return (B.y-A.y) / (B.x - A.x);
}

float yInterceptFor(float slope, Point A) {
  return (A.y - (slope * A.x));
}

float map(float range1_A, float range1_B, float range2_A, float range2_B, float value) {
    float  inMin = range1_A;
    float  inMax = range1_B;

    float  outMin = range2_A;
    float  outMax = range2_B;

    float input = value;
    float output = outMin + (outMax - outMin) * (input - inMin) / (inMax - inMin);

    return output;
}

Point XYAltitude(float leg1, float leg2, float base) {

  float width = WIDTH(leg1,leg2,base); 
  float height = HEIGHT(width,leg1);
  return p(width, height);
}

Point APEX_OF(scaleneTetrahedron shape) {
  Point altitude1 = XYAltitude(shape.legA,shape.legB, shape.edgeA);//Getting the x position of the altitude of faceA and the height of the altitude. 
  printPoint("Altitude face:",altitude1);
  float 
  x = altitude1.x,
  baseX1 = x,
  baseX2 = x,
  baseY1 = 0,
  baseY2 = 10
  ; 

  float slopeBase = slopeFor(shape.vertexBaseC, shape.vertexBaseB), yIntBase = yInterceptFor(slopeBase,shape.vertexBaseB);
  printf("slope is:%f ,yint is:%f, point of intersection:%f\n",slopeBase,yIntBase, (slopeBase * x)+yIntBase);
  Point intersectionBase = p(x, (slopeBase * x) + yIntBase);


  printPoint("IntersectionBase:",intersectionBase);

  float zIntersectionBase = (slopeBase * x) + yIntBase;//it is "y" because we are switching from a topdown to a side view
  float zHypotenuse = (shape.edgeC* intersectionBase.y)/shape.vertexBaseC.y; //THIS IS THROWING OFF THE MEASUREMENT: sqrtf(SQUARE(zIntersectionBase) + SQUARE(altitude1.y));
  Point zAltitude   = XYAltitude(altitude1.y,zHypotenuse,zIntersectionBase);
  float theta       = Rad_To_Deg(atan2(zAltitude.x,zAltitude.y));//Here's where I am having trouble.
  float y = Rad_To_Deg(sin(theta)) * altitude1.x;
  float z = Rad_To_Deg(cos(theta)) * altitude1.x;
  printFloat(theta);
  Point rtd;
  rtd.x = x;
  rtd.z = y; //Only now did I learn that z and y are swapped in 3D. But, this is no problem due to abstraction. 
  rtd.y = z;

  return rtd;
}

int main(int argc, const char *argv[]){
  // srand(time(NULL));   

  Point vertexA  = p(0,0); 
  Point vertexB  = p(3,0.f);
  Point vertexC  = p(1.5,2.6); 
  Point apex =   pZ(1.5,0.87,2.45);

  float baseA = DISTANCE(vertexA,vertexB);
  float baseB = DISTANCE(vertexB,vertexC);
  float baseC = DISTANCE(vertexC,vertexA);
  float legA  = DISTANCE(vertexA,apex);
  float legB  = DISTANCE(vertexB,apex);
  float legC  = DISTANCE(vertexC,apex);

  scaleneTetrahedron toSend;
  toSend.edgeA = baseA;
  toSend.edgeB = baseB;
  toSend.edgeC = baseC;

  toSend.legA = legA; 
  toSend.legB = legB;
  toSend.legC = legC;

  toSend.vertexBaseA = vertexA;
  toSend.vertexBaseB = vertexB;
  toSend.vertexBaseC = vertexC;
  printPoint("APEX:",APEX_OF(toSend));

  return 0;

}

Solution

  • USING TRIGONOMETRY

    1. Compute the lengths of the altitudes HA and HD in their respective face from the sides.

    2. Compute the angle AHD by the cosine formula.

    USING ANALYTICAL GEOMETRY

    1. Project A orthogonally onto BC to get H: BH = ((AB.BC)/BC²).BC (bold are vectors)

    2. Compute the angle from cos AHD = AH.HD/||AH||.||HD||