"Faces" button in WebGl that
toggles between assigning a single color for each vertex of a face
and assigning a different color for each vertex so colors are
interpolated across each face
package com;
import java.util.ArrayList;
public class ArrayWithExponentAsIndexPolynomial implements PolynomialInterface
{
int polynomial[];
int highExp;
ArrayWithExponentAsIndexPolynomial()
{
polynomial=new int[200];
}
ArrayWithExponentAsIndexPolynomial(String pol)
{
polynomial=new int[200];
highExp=0;
int co=0;//Coefficient
int exp=0;//exponent
//Convert the polynomial string into linked list of polynomial terms
for(int i=0;i<pol.length();i++)
{
co=0;
exp=0;
//Find coefficient
while(pol.charAt(i)!='x' && pol.charAt(i)!='X' )
{
if(pol.charAt(i)=='-')
{
i++;
while(i<pol.length())
{
if(pol.charAt(i)!='x' && pol.charAt(i)!='X' )
{
String sub=pol.substring(i,i+1);
co=co*10+Integer.parseInt(sub);
}
else
break;
i++;
}
co=co*-1;
}
else if (pol.charAt(i)=='+')
{
i++;
}
else
{
String sub=pol.substring(i,i+1);
co=co*10+Integer.parseInt(sub);
i++;
}
if(i>=pol.length())
break;
}
i++;//skip x
if(i==pol.length())
{
if(pol.charAt(i-1)=='x' || pol.charAt(i-1)=='X')
exp=1;
}
i++;//skip ^
if(i<pol.length())
while(pol.charAt(i)!='-' && pol.charAt(i)!='+' )
{
String sub=pol.substring(i,i+1);
exp=exp*10+Integer.parseInt(sub);
i++;
if(i>=pol.length())
break;
}
if(highExp<exp)
highExp=exp;
addATerm(exp,co);
i--;
}
}
// stores the coefficient at index(exp)
void addATerm(int exp,int co)
{
// store the coefficient at index(exp)
polynomial[exp]=co;
}
int getHigh()
{
return highExp;
}
@Override
//Adds two polynomials and returns the resultant polynomial
public PolynomialInterface add(PolynomialInterface other)
{
int high;
ArrayWithExponentAsIndexPolynomial temp=new ArrayWithExponentAsIndexPolynomial();
ArrayWithExponentAsIndexPolynomial otherPoly=(ArrayWithExponentAsIndexPolynomial)other;
if(this.getHigh()<otherPoly.getHigh())
{
high=otherPoly.getHigh();
temp.highExp=otherPoly.getHigh();
}
else
{
high=this.getHigh();
temp.highExp=this.getHigh();
}
for(int i=0;i<=high;i++)
{
if(this.polynomial[i]!=0 && otherPoly.polynomial[i]!=0)
{
temp.polynomial[i]=this.polynomial[i]+otherPoly.polynomial[i];
}
else if (this.polynomial[i]==0 && otherPoly.polynomial[i]!=0)
{
temp.polynomial[i]=otherPoly.polynomial[i];
}
else if (this.polynomial[i]!=0 && otherPoly.polynomial[i]==0)
{
temp.polynomial[i]=this.polynomial[i];
}
}
return temp;
}
@Override
//Substracts one polynomial from another and returns the resultant polynomial
public PolynomialInterface subtract(PolynomialInterface other)
{
int high;
ArrayWithExponentAsIndexPolynomial temp=new ArrayWithExponentAsIndexPolynomial();
ArrayWithExponentAsIndexPolynomial otherPoly=(ArrayWithExponentAsIndexPolynomial)other;
if(this.getHigh()<otherPoly.getHigh())
{
high=otherPoly.getHigh();
temp.highExp=otherPoly.getHigh();
}
else
{
high=this.getHigh();
temp.highExp=this.getHigh();
}
for(int i=0;i<=high;i++)
{
if(this.polynomial[i]!=0 && otherPoly.polynomial[i]!=0)
{
temp.polynomial[i]=this.polynomial[i]-otherPoly.polynomial[i];
}
else if (this.polynomial[i]==0 && otherPoly.polynomial[i]!=0)
{
temp.polynomial[i]=0-otherPoly.polynomial[i];
}
else if (this.polynomial[i]!=0 && otherPoly.polynomial[i]==0)
{
temp.polynomial[i]=this.polynomial[i];
}
}
return temp;
}
public String toString()
{
String poly="";
//Convert the linked list into polynomial string
for(int i=this.getHigh();i>=0;i--)
{
if(polynomial[i]!=0)
{
if(i==1)
{
if(polynomial[i]<0)
poly=poly+"-"+polynomial[i]*-1+"x";
else
poly=poly+polynomial[i]+"x";
}
else if(i!=0)
{
if(polynomial[i]<0)
poly=poly+"-"+polynomial[i]*-1+"x^"+i;
else
{
if(i!=this.getHigh())
poly=poly+"+"+polynomial[i]+"x^"+i;
else
poly=poly+polynomial[i]+"x^"+i;
}
}
else
{
if(polynomial[i]<0)
poly=poly+"-"+polynomial[i]*-1;
else
poly=poly+"+"+polynomial[i];
}
}
}
return poly;
}
}
"Faces" button in WebGl that toggles between assigning a single color for each vertex of a...
In WebGL, we can associate a color with each vertex. If the endpoints of a line segment have different colors assigned to them, WebGL will interpolate between the colors as it renders the line segment. It will do the same for polygons. Use this property to display the Maxwell triangle: an equilateral triangle whose vertices are red, green, and blue. What is the relationship between the Maxwell triangle and the color cube?
One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we will look at ways in which we can model geometric objects comprised of polygons. Here, we want to examine the interactive part. Let’s start by writing an application that will let the user specify a series of axis- aligned rectangles interactively. Each rectangle can be defined by two mouse positions at diagonally opposite corners. Consider the event listener canvas.addEventListener("mousedown", function() { gl.bindBuffer(gl.ARRAY_BUFFER, vBuffer); if...
For this project, each part will be in its oun matlab script. You will be uploading a total 3 m files. Be sure to make your variable names descriptive, and add comments regularly to describe what your code is doing and hou your code aligns with the assignment 1 Iterative Methods: Conjugate Gradient In most software applications, row reduction is rarely used to solve a linear system Ar-b instead, an iterative algorithm like the one presented below is used. 1.1...
Read “Instituionalizing our Demise: America vs Multiculturalism” by
Roger Kimball on pg 268 and “Reinventing America” Call for a new
national indentity” by Elizabeth Martinez on pg 275. Create a
double entry notebook for each reading selection It should be
atleast five observation and responses.
wric 268 PART 2 essay pro. exactly how and why their authors disagree. Instead of with parties in conflict as mediators do, you will nt of view designed to appeal to both sides, mediatn posing...