Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e379a57

Browse files
Merge pull request fnplus#289 from siddharthrajaraja/master
COMPUTATIONAL GEOMETRY
2 parents 0b70c8f + 20bdd1b commit e379a57

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

‎Algorithms/COMPUTATIONAL_GEOMETRY.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Basically in this algorithm two end points of two line segments are taken and it checks whether the two line segments intersects or not!!
2+
3+
INPUT (X,Y) for two Line Segments
4+
OUTPUT :
5+
"YES" (if Line Segments interdects)
6+
or
7+
"NO" (if Line Segments do not interdects)

‎Algorithms/COMPUTATIONAL_GEOMETRY.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import numpy as np
2+
3+
def DIRECTION(pi,pj,pk):
4+
a=np.subtract(pk,pi)
5+
b=np.subtract(pj,pi)
6+
return np.cross(a,b)
7+
8+
def on_segment(pi,pj,pk):
9+
pi=list(pi)
10+
pj=list(pj)
11+
p=[]
12+
p.append(pi)
13+
p.append(pj)
14+
15+
P=list(zip(*p))
16+
17+
18+
if min(P[0])<=pk[0]<=max(P[0]) and min(P[1])<=pk[1]<=max(P[1]):
19+
return True
20+
return False
21+
22+
23+
24+
if __name__=="__main__":
25+
p1=np.array(list(map(int,input("ENTER (X1,Y1) of LINE SEGMENT 1: ").split())))
26+
p2=np.array(list(map(int,input("ENTER (X2,Y2) of LINE SEGMENT 1: ").split())))
27+
p3=np.array(list(map(int,input("ENTER (X3,Y3) of LINE SEGMENT 2: ").split())))
28+
p4=np.array(list(map(int,input("ENTER (X4,Y4) of LINE SEGMENT 2: ").split())))
29+
30+
d1=DIRECTION(p3,p4,p1)
31+
d2=DIRECTION(p3,p4,p2)
32+
d3=DIRECTION(p1,p2,p3)
33+
d4=DIRECTION(p1,p2,p4)
34+
35+
if ((d1>0 and d2<0) or (d1<0 and d2>0)) and ((d3>0 and d4<0) or (d3<0 and d4>0)):
36+
print("YES")
37+
elif d1==0 and on_segment(p3,p4,p1):
38+
print("YES")
39+
elif d2==0 and on_segment(p3,p4,p2):
40+
print("YES")
41+
elif d3==0 and on_segment(p1,p2,p3):
42+
print("YES")
43+
elif d4==0 and on_segment(p1,p2,p4):
44+
print("YES")
45+
else:
46+
print("NO")
47+

‎Algorithms/sieve.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SIEVE OF ERASTOSTHENES IS TO FIND all prime numbers till value of n specified
2+
3+
INPUT : n (max limit)
4+
5+
OUTPUT : All prime numbers

‎Algorithms/sieve.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import math
2+
if __name__=="__main__":
3+
4+
5+
n=int(input())
6+
7+
Prime=[]
8+
9+
for i in range(0,n+1):
10+
Prime.append(True)
11+
Prime[0]=False
12+
Prime[1]=False
13+
14+
for i in range(2,int(math.sqrt(n)+1)):
15+
if Prime[i]==True:
16+
j=2
17+
while i*j<=n:
18+
19+
Prime[i*j]=False
20+
j=j+1
21+
s=0
22+
for i in range(2,n+1):
23+
if Prime[i]==True:
24+
print(i)
25+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /