Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am unsure about how to complete this code. Problem: Compute color of triangle

ID: 3756655 • Letter: I

Question

I am unsure about how to complete this code.

Problem:

Compute color of triangle in which point lives.
The color should be set by linear interpolation of the vertex colors based on the barycentric coordinates of the point.

Input: uvw = {u,v,w} and vertex colors c1, c2, c3 each as {r,g,b} colors
Output: color {r,g,b}

To Do: complete this function.

Tip: for accessing vertex colors for a triangle (triangle # inTri)
i1 = tris[[inTri,1]]; -- grabs the index of the point that is the first vertex of the triangle
vcolors[[i1]] -- the color of vertex i1

This is the code skeleton given:

computeColor[uvw_, c1_, c2_, c3_] := (
Return[color]
);

Explanation / Answer

Please go through the following code written in C language and ask for any help if you have any doubt.

#include<stdio.h>

int computeColor(int u,int v, int w ,char c1, char c2, char c3);

int main()

{

int u,v,w;

char c1,c2,c3,ch;

printf(" Enter the color1 of rambo: ");

scanf("%s",&c1);

printf(" Enter the color2 of rambo: ");

scanf("%s",&c2);

printf(" Enter the color3 of rambo: ");

scanf("%s",&c3);

printf(" Enter the coordinates of u: ");

scanf("%d",&u);

printf(" Enter the coordinates of v: ");

scanf("%d",&v);

printf(" Enter the coordinates of w: ");

scanf("%d",&w);

printf("Enter a choice of color such as R,G or B: );

scanf("%s",&ch);

switch(ch)

{

case R:

printf(" Color is Red and vertex is %d",u);

break;

case G:

printf("Color is Green and vertex is %d",v);

break;

case B:

printf("Color is Blue and vertex is %d",w);

break;

default:

printf(" Wrong choice entered please run the program again ");

break;

}

return 0;

}

int computeColor(int u,int v, int w ,char c1, char c2, char c3)

{
if(u==v || u==w)

{

printf("Color is %s",c1);

}

else if(v==u || v==w)

{

printf("Color is %s",c2);

}

else

{

printf(" Color is %s ", c3);

}

return 0;
}

//Do not forget to Thumbs up and ask for any help if you feel the need

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote