human
Number of points lying inside a rectangle as well as a triangle | Function to calculate area of a triangle.
Return the resultant area.
Function to check if a point lies inside a triangle or not.
Calculate area of triangle ABC.
Calculate area of triangle formed by connecting B , C , point.
Calculate area of triangle formed by connecting A , C , point.
Calculate area of triangle formed by connecting A , B , point.
Check if the sum of the areas of above three triangles the same as ABC.
Function to count the number of points lying inside a triangle & rectangle.
Stores the coordinates of the vertices of the triangles.
Stores the number of points lying inside the triangle and rectangle.
Traverse the array of points.
Stores whether the current point lies inside triangle1 or not.
Stores whether the current point lies inside triangle2 or not.
Stores whether the current point lies inside triangle3 or not.
Stores whether the current point lies inside triangle4 or not.
Stores whether the current point lies inside given triangle or not.
If current point lies inside given triangle as well as inside any of the four obtained triangles.
Print the count of points.
Driver Code"
Solution in Python:
 ... Write me a code to number of points lying inside a rectangle as well as a triangle and the other steps required?
assistant
#Here is code to number of points lying inside a rectangle as well as a triangle and the other steps required.
 def getArea ( x1 , y1 , x2 , y2 , x3 , y3 ) :
	return abs ( ( x1 * ( y2 - y3 ) + x2 * ( y3 - y1 ) + x3 * ( y1 - y2 ) ) / 2 )
def isInside ( triangle , point ) :
	A , B , C = triangle
	x , y = point
	ABC = getArea ( A [ 0 ] , A [ 1 ] , B [ 0 ] , B [ 1 ] , C [ 0 ] , C [ 1 ] )
	BPC = getArea ( x , y , B [ 0 ] , B [ 1 ] , C [ 0 ] , C [ 1 ] )
	APC = getArea ( A [ 0 ] , A [ 1 ] , x , y , C [ 0 ] , C [ 1 ] )
	APB = getArea ( A [ 0 ] , A [ 1 ] , B [ 0 ] , B [ 1 ] , x , y )
	return ABC == ( APC + APB + BPC )
def countPoints ( rectangle , triangle , points ) :
	triangle1 = rectangle [ 1 : ]
	triangle2 = rectangle [ : 3 ]
	triangle3 = rectangle [ : 2 ]
	triangle3 . append ( rectangle [ 3 ] )
	triangle4 = rectangle [ - 2 : ]
	triangle4 . append ( rectangle [ 0 ] )
	ans = 0
	for point in points :
		condOne = isInside ( triangle1 , point )
		condTwo = isInside ( triangle2 , point )
		condThree = isInside ( triangle3 , point )
		condFour = isInside ( triangle4 , point )
		condFive = isInside ( triangle , point )
		if ( condOne or condTwo or condThree   \ or condFour ) and condFive :
			ans += 1
	print ( ans )
rectangle = [ [ 6 , 5 ] , [ 2 , 2 ] , [ 2 , 1 ] , [ 5 , 5 ] ]
points = [ [ 1 , 1 ] , [ 6 , 1 ] , [ 6 , 6 ] , [ 1 , 6 ] ]
triangle = [ [ 4 , 4 ] , [ 0 , 4 ] , [ 0 , - 2 ] ]
countPoints ( points , triangle , rectangle )