2019-02-12

Feb 13 In-Class Exercise Thread.

Hey Everyone,
Post your solutions to the Feb 13 In-Class Exercise to this thread.
Best,
Chris
Hey Everyone, Post your solutions to the Feb 13 In-Class Exercise to this thread. Best, Chris

-- Feb 13 In-Class Exercise Thread
Hi,
 function onTriangle(p_1, p_2, p_3, p):
     for i, j in {1,2,3}, i < j:
         if (p_j-p_i) x (p-p_i) = 0:
             return |p_j-p_i| <= |p-p_i| and <p_j-p_i, p-p_i> > 0 // check that point is in line segment
     return false
 function inTriangle(p_1, p_2, p_3, p):
     if sign(<p_2 - p_1, p_1 - p>) != sign(<p_3 - p_1, p_1 - p>):
         return  false
     if sign(<p_3 - p_2, p_2 - p>) != sign(<p_1 - p_2, p_2 - p>):
         return  false
     if sign(<p_1 - p_3, p_3 - p>) != sign(<p_2 - p_3, p_3 - p>):
         return  false
     return true
(Edited: 2019-02-13)
Hi, function onTriangle(p_1, p_2, p_3, p): for i, j in {1,2,3}, i < j: if (p_j-p_i) x (p-p_i) = 0: return |p_j-p_i| <= |p-p_i| and <p_j-p_i, p-p_i> > 0 // check that point is in line segment return false function inTriangle(p_1, p_2, p_3, p): if sign(<p_2 - p_1, p_1 - p>) != sign(<p_3 - p_1, p_1 - p>): return false if sign(<p_3 - p_2, p_2 - p>) != sign(<p_1 - p_2, p_2 - p>): return false if sign(<p_1 - p_3, p_3 - p>) != sign(<p_2 - p_3, p_3 - p>): return false return true

-- Feb 13 In-Class Exercise Thread
2/ double area(x1,y1,x2,y2,x3,y3){
  x= (x1*(y2-y3) + x2*(y3-y1)+x3*(y1-y2))/2.0)
}
inside (x,y,x1,y1,x2,y2,x3,y3){
   areaABC= area(x1,y1,x2,y2,x3,y3)
   areaABP=area(x1,y1,x2,y2,x,y)
   areaPBC=area(x,y,x2,y2,x3,y3)
   areaBCP=area(x2,y2,x3,y3,x,y)
   return (areaABC==areaABP+areaPBC+areaBCP)
}
(Edited: 2019-02-13)
2/ double area(x1,y1,x2,y2,x3,y3){ x= (x1*(y2-y3) + x2*(y3-y1)+x3*(y1-y2))/2.0) } inside (x,y,x1,y1,x2,y2,x3,y3){ areaABC= area(x1,y1,x2,y2,x3,y3) areaABP=area(x1,y1,x2,y2,x,y) areaPBC=area(x,y,x2,y2,x3,y3) areaBCP=area(x2,y2,x3,y3,x,y) return (areaABC==areaABP+areaPBC+areaBCP) }
2019-02-14

-- Feb 13 In-Class Exercise Thread
Hi all, I have not tested this code, it is just pseudo code for my attempt to solve the 2 problems given in class. It has been a while since I took calc 3, so pls forgive me.
//coords[] is an array of 3 vectors which the triangle is composed of function pointOnTriangleBoundary (p, coords[]) { for (int i = 0; i 0 } function pointInsideTriangle (p, coords[]) { insideTriangle = true; onSamePlane = checkIfPointIsOnPlane(p, coords[]) if (onSamePlane) for (int i = 0; i
sources: https://math.stackexchange.com/questions/1156983/find-the-equation-of-the-plane-knowing-that-it-passes-through-3-points
(Edited: 2019-02-14)
Hi all, I have not tested this code, it is just pseudo code for my attempt to solve the 2 problems given in class. It has been a while since I took calc 3, so pls forgive me. <nowiki> //coords[] is an array of 3 vectors which the triangle is composed of function pointOnTriangleBoundary (p, coords[]) { for (int i = 0; i<coords.size(); i++) for (int j = 0; j<coords.size(); j++) //this checks if any of the lines on the triangle are parallel with a line //created by p and some point on the triangle and that the angle between //them is zero; this is the definition of when the cross product of 2 //vectors = 0 if (p-coords[i] X coords[j] - coords[i] == 0 && j != i) //if found to be true, then check if both lines are going in the same // direction from both sides return (p - coords[j])*(coords[i] - coords[j]) > 0 && (p - coords[i])*(coords[j] - coords[i]) > 0 } function pointInsideTriangle (p, coords[]) { insideTriangle = true; onSamePlane = checkIfPointIsOnPlane(p, coords[]) if (onSamePlane) for (int i = 0; i<coords.size(); i++) for (int j = 0; j<coords.size(); j++) for (int k = 0; k<coords.size(); k++) //only run the check if i, j, k are distinct if (j!=i && k!=j && k!=i) //if the angle between the line made by p and some point on the //triangle and an adjacent edge is less than the angle two adjacent //edges from all sides of the triangle, then p is inside the triangle if (angleBetween(p - coord[i], coord[j] - coord[i]) > angleBetween(coord[k] - coord[i], coord[j] - coord[i])) insideTriangle = false; break; else insideTriangle = false; return insideTriangle; } function checkIfPointIsOnPlane(p, coords[]){ v1 = coords[1] - coords[0] v2 = coords[2] - coords[0] normal = v1 X v2 if (normal * (p - coord[0]) == 0 ) return true else return false } function angleBetween (a, b) { return inverseCos(a.dot(b) / a.magnitude()*b.magnitude()) } </nowiki> sources: https://math.stackexchange.com/questions/1156983/find-the-equation-of-the-plane-knowing-that-it-passes-through-3-points
2019-02-18

-- Feb 13 In-Class Exercise Thread
def findSide(Point a, Point b):
	# Point class has x and y fields
	return ((a.x - b.x) ** 2 + (a.y - b.y) ** 2) ** (1/2)
def findArea(Point a, Point b, Point c):
	# Point class has x and y fields
	sideA = findSide(a, b)
	sideB = findSide(b, c)
	sideC = findSide(a, c)
	s = (sideA + side B + side C)/2
	return (s*(s-a)*(s-b)*(s-c)) ** 0.5; 
def onBoundary(Point a, Point b, Point c, Point test):
	# Point class has x and y fields
	areaABP = findArea(a, b, test)
	areaACP = findArea(b, c, test)
	areaBCP = findArea(a, c, test)
	return (areaABP == 0 || areaACP == 0 || areaBCP == 0)
def inBoundary(Point a, Point b, Point c, Point test):
	# Point class has x and y fields
	areaABP = findArea(a, b, test)
	areaACP = findArea(b, c, test)
	areaBCP = findArea(a, c, test)
	return ((area(a, b, c)) == (areaABP + areaACP + areaBCP))
	
def findSide(Point a, Point b): # Point class has x and y fields return ((a.x - b.x) ** 2 + (a.y - b.y) ** 2) ** (1/2) def findArea(Point a, Point b, Point c): # Point class has x and y fields sideA = findSide(a, b) sideB = findSide(b, c) sideC = findSide(a, c) s = (sideA + side B + side C)/2 return (s*(s-a)*(s-b)*(s-c)) ** 0.5; def onBoundary(Point a, Point b, Point c, Point test): # Point class has x and y fields areaABP = findArea(a, b, test) areaACP = findArea(b, c, test) areaBCP = findArea(a, c, test) return (areaABP == 0 || areaACP == 0 || areaBCP == 0) def inBoundary(Point a, Point b, Point c, Point test): # Point class has x and y fields areaABP = findArea(a, b, test) areaACP = findArea(b, c, test) areaBCP = findArea(a, c, test) return ((area(a, b, c)) == (areaABP + areaACP + areaBCP))
X