We can define $ ^{n}{{C}_{r}} $ as below:
$ ^{n}{{C}_{r}}=\dfrac{n!}{r!\times [n-r]!} $
Complete step-by-step answer:
To draw we need three points in which two points can be collinear only or all three points can be non collinear.
In given questions total numbers of points is 12 out of which 6 are collinear and 6 non collinear. So there are following cases to draw a triangle
Case 1:
We can choose all three points from 6 non collinear points.
So the number of ways to select three points from 6 points is $ ^{6}{{C}_{3}} $ .
We can find value of $ ^{6}{{C}_{3}} $ as below:
$ {{\Rightarrow }^{6}}{{C}_{3}}=\dfrac{6!}{3!\times [6-3]!} $ $ \left\{ {{\because }^{n}}{{C}_{r}}=\dfrac{n!}{r!\times [n-r]!} \right\} $
$ {{\Rightarrow }^{6}}{{C}_{3}}=\dfrac{6!}{3!\times 3!} $
$ {{\Rightarrow }^{6}}{{C}_{3}}=\dfrac{6\times 5\times 4\times 3!}{3\times 2\times 1\times 3!} $
$ {{\Rightarrow }^{6}}{{C}_{3}}=20 $
Case 2:
Now we can choose two points from 6 non collinear points and 1 point from 6 collinear points.
So number of ways to select 2 points from 6 non collinear points and 1 point from 6 collinear points is \[^{6}{{C}_{2}}{{\times }^{6}}{{C}_{1}}\]
We can find value of \[^{6}{{C}_{2}}{{\times }^{6}}{{C}_{1}}\] as below:
\[{{\Rightarrow }^{6}}{{C}_{2}}{{\times }^{6}}{{C}_{1}}=\dfrac{6!}{2!\times [6-2]!}\times \dfrac{6!}{1!\times [6-1]!}\]
\[{{\Rightarrow }^{6}}{{C}_{2}}{{\times }^{6}}{{C}_{1}}=\dfrac{6!}{2!\times 4!}\times \dfrac{6!}{1!\times 5!}\]
\[{{\Rightarrow }^{6}}{{C}_{2}}{{\times }^{6}}{{C}_{1}}=\dfrac{6\times 5\times 4!}{2\times 1\times 4!}\times \dfrac{6\times 5!}{1\times 5!}\]
\[{{\Rightarrow }^{6}}{{C}_{2}}{{\times }^{6}}{{C}_{1}}=15\times 6=90\]
Case 3:
Now we can choose 1 point from 6 non collinear points and 2 point from 6 collinear points.
So number of ways to select 1 points from 6 non collinear points and 2 point from 6 collinear points is \[^{6}{{C}_{1}}{{\times }^{6}}{{C}_{2}}\]
We can find value of \[^{6}{{C}_{1}}{{\times }^{6}}{{C}_{2}}\] as below:
\[{{\Rightarrow }^{6}}{{C}_{1}}{{\times }^{6}}{{C}_{2}}=\dfrac{6!}{1!\times [6-1]!}\times \dfrac{6!}{2!\times [6-2]!}\]
\[{{\Rightarrow }^{6}}{{C}_{1}}{{\times }^{6}}{{C}_{2}}=\dfrac{6!}{1!\times 5!}\times \dfrac{6!}{2!\times 4!}\]
\[{{\Rightarrow }^{6}}{{C}_{1}}{{\times }^{6}}{{C}_{2}}=\dfrac{6\times 5!}{1\times 5!}\times \dfrac{6\times 5\times 4!}{2\times 1\times 4!}\]
\[{{\Rightarrow }^{6}}{{C}_{1}}{{\times }^{6}}{{C}_{2}}=6\times 15=90\]
Hence total number of possible triangles which can be formed from 12 points out of which 6 points are collinear is = 20+90+90 = 200
Note:To draw a triangle we need three points. But we cannot draw a triangle from three collinear points.
In general, the factorial of n can be defined as a product of all integers from n to 1. We can write it as
$n!=n[n-1][n-2][n-3]................................3.2.1$
It is defined only for positive integers.
function triangleContains[ax, ay, bx, by, cx, cy, x, y] {
let det = [bx - ax] * [cy - ay] - [by - ay] * [cx - ax]
return det * [[bx - ax] * [y - ay] - [by - ay] * [x - ax]] > 0 &&
det * [[cx - bx] * [y - by] - [cy - by] * [x - bx]] > 0 &&
det * [[ax - cx] * [y - cy] - [ay - cy] * [x - cx]] > 0
}
let width = 500, height = 500
// clockwise
let triangle1 = {
A : { x: 10, y: -10 },
C : { x: 20, y: 100 },
B : { x: -90, y: 10 },
color: '#f00',
}
// counter clockwise
let triangle2 = {
A : { x: 20, y: -60 },
B : { x: 90, y: 20 },
C : { x: 20, y: 60 },
color: '#00f',
}
let scale = 2
let mouse = { x: 0, y: 0 }
// DRAW >
let wrapper = document.querySelector['div.wrapper']
wrapper.onmousemove = [{ layerX:x, layerY:y }] => {
x -= width / 2
y -= height / 2
x /= scale
y /= scale
mouse.x = x
mouse.y = y
drawInteractive[]
}
function drawArrow[ctx, A, B] {
let v = normalize[sub[B, A], 3]
let I = center[A, B]
let p
p = add[I, rotate[v, 90], v]
ctx.moveTo[p.x, p.y]
ctx.lineTo[I.x, I .y]
p = add[I, rotate[v, -90], v]
ctx.lineTo[p.x, p.y]
}
function drawTriangle[ctx, { A, B, C, color }] {
ctx.beginPath[]
ctx.moveTo[A.x, A.y]
ctx.lineTo[B.x, B.y]
ctx.lineTo[C.x, C.y]
ctx.closePath[]
ctx.fillStyle = color + '6'
ctx.strokeStyle = color
ctx.fill[]
drawArrow[ctx, A, B]
drawArrow[ctx, B, C]
drawArrow[ctx, C, A]
ctx.stroke[]
}
function contains[{ A, B, C }, P] {
return triangleContains[A.x, A.y, B.x, B.y, C.x, C.y, P.x, P.y]
}
function resetCanvas[canvas] {
canvas.width = width
canvas.height = height
let ctx = canvas.getContext['2d']
ctx.resetTransform[]
ctx.clearRect[0, 0, width, height]
ctx.setTransform[scale, 0, 0, scale, width/2, height/2]
}
function drawDots[] {
let canvas = document.querySelector['canvas#dots']
let ctx = canvas.getContext['2d']
resetCanvas[canvas]
let count = 1000
for [let i = 0; i < count; i++] {
let x = width * [Math.random[] - .5]
let y = width * [Math.random[] - .5]
ctx.beginPath[]
ctx.ellipse[x, y, 1, 1, 0, 0, 2 * Math.PI]
if [contains[triangle1, { x, y }]] {
ctx.fillStyle = '#f00'
} else if [contains[triangle2, { x, y }]] {
ctx.fillStyle = '#00f'
} else {
ctx.fillStyle = '#0003'
}
ctx.fill[]
}
}
function drawInteractive[] {
let canvas = document.querySelector['canvas#interactive']
let ctx = canvas.getContext['2d']
resetCanvas[canvas]
ctx.beginPath[]
ctx.moveTo[0, -height/2]
ctx.lineTo[0, height/2]
ctx.moveTo[-width/2, 0]
ctx.lineTo[width/2, 0]
ctx.strokeStyle = '#0003'
ctx.stroke[]
drawTriangle[ctx, triangle1]
drawTriangle[ctx, triangle2]
ctx.beginPath[]
ctx.ellipse[mouse.x, mouse.y, 4, 4, 0, 0, 2 * Math.PI]
if [contains[triangle1, mouse]] {
ctx.fillStyle = triangle1.color + 'a'
ctx.fill[]
} else if [contains[triangle2, mouse]] {
ctx.fillStyle = triangle2.color + 'a'
ctx.fill[]
} else {
ctx.strokeStyle = 'black'
ctx.stroke[]
}
}
drawDots[]
drawInteractive[]
// trigo
function add[...points] {
let x = 0, y = 0
for [let point of points] {
x += point.x
y += point.y
}
return { x, y }
}
function center[...points] {
let x = 0, y = 0
for [let point of points] {
x += point.x
y += point.y
}
x /= points.length
y /= points.length
return { x, y }
}
function sub[A, B] {
let x = A.x - B.x
let y = A.y - B.y
return { x, y }
}
function normalize[{ x, y }, length = 10] {
let r = length / Math.sqrt[x * x + y * y]
x *= r
y *= r
return { x, y }
}
function rotate[{ x, y }, angle = 90] {
let length = Math.sqrt[x * x + y * y]
angle *= Math.PI / 180
angle += Math.atan2[y, x]
x = length * Math.cos[angle]
y = length * Math.sin[angle]
return { x, y }
}
* {
margin: 0;
}
html {
font-family: monospace;
}
body {
padding: 32px;
}
span.red {
color: #f00;
}
span.blue {
color: #00f;
}
canvas {
position: absolute;
border: solid 1px #ddd;
}
red triangle is clockwise
blue triangle is couter clockwise