Author |
Topic: SIN, COS, RAD.. what about depth? (Read 281 times) |
|
michael
Senior Member
member is offline


Posts: 335
|
 |
SIN, COS, RAD.. what about depth?
« Thread started on: Nov 20th, 2017, 12:35am » |
|
I pretty much got SIN , COS and RAD figured out.
But it would be helpful if I could figure the math on perhaps a simple line with one end moving from the side towards me and back to the distance?
Anyone willing to show a super simple example of a line that does that? I am not sure what math is needed.
Code: MODE 8
REM if you are reading this, you are seeing an experiment in progress.. unknown effects (ok its known)
GCOL 3
PROC_myellipse(200,200,100,100):GCOL 14:PROC_myellipse(200,200,95,95)
PROC_myellipse(200,500,200,100)
PROCangdra(2,100,700):REM 2-is for setting 400,400 as start screen location
PROCangdra(0,45,50): REM 45 degrees (up) 50 points
PROCangdra(0,45,50): REM right 45 degrees go 50 points
PROCangdra(0,45,50): REM right 45 degrees go 50 points
PROCangdra(0,45,50): REM right 45 degrees go 50 points
PROCangdra(0,45,50): PROCangdra(0,45,50): PROCangdra(0,45,50): PROCangdra(0,45,50)
REM draw a line from 300,300 to 100 points in a 45 degree angle
LINE 200,300,200+FNhdd(180,100),300+FNvdd(180,100):REM 0 degrees is up from center & right is positivedd
VDU 23,23,3|
dv%=0:i=0
FOR dv%=1 TO 150 STEP 2
i+=2.5
COLOUR 0,250-i,200-i,210-i : GCOL 0
PROC_myellipse(800,500,0+dv%,0+dv%)
NEXT dv%
t%=0
REPEAT
FOR t%=1 TO 360
GCOL 15
LINE 200,200,200+FNhdd(t%,80),200+FNvdd(t%,80)
WAIT 5
COLOUR 0,0,0,0:GCOL 0
LINE 200,200,200+FNhdd(t%,80),200+FNvdd(t%,80)
NEXT t%
UNTIL FALSE
END
REM horizontal degrees and length
DEF FNhdd(degrees%,sx%)
vs%=sx%*SIN RAD(degrees%)
=vs%
REM vertical degrees and length
DEF FNvdd(degrees%,sy%)
vy%=sy%*COS RAD(degrees%)
=vy%
REM this is kinda like a turtle control for only the angle. -num will turn left and +num will turn right
DEFPROCangdra(ud%,n%,d%):REM ud%- 0 down 1 up ( n% +or- angle. d%=distance)
REM if ud%= 2 THEN MOVE n%,d% instead of ange and distance
PRIVATE ang%,hp%,vp%
IF ud%=2 THEN hp%=n%:vp%=d%
IF ud%=0 OR ud%=1 THEN
ang%+=n%
IF ud%=0 THEN LINE hp%,vp%,hp%+FNhdd(ang%,d%),vp%+FNvdd(ang%,d%):ud%=1
IF ud%=1 THEN hp%=hp%+FNhdd(ang%,d%):vp%=vp%+FNvdd(ang%,d%):REM PEN UP 1
ENDIF
ENDPROC
REM x,y sizex, sizey
DEF PROC_myellipse(x,y,sx,sy)
LOCAL xs%,yc%,d%
FOR d%=0 TO 360
LINE x+FNhdd(d%,sx),y+FNvdd(d%,sy),x+FNhdd(d%,sx),y+FNvdd(d%,sy):REM FNvdd(degrees,distance) FNhdd(degrees,dist)
NEXT d%
ENDPROC
REM PROC_tri(x,y,size,R,G,B,dimmer)
DEFPROC_tri(x,y,s,r%,g%,b%,d_i%)
REM center will be x,y
LOCAL x%,skip%
skip%=FALSE
FOR x%=0 TO s
r%=r%-d_i%
g%=g%-d_i%
b%=b%-d_i%
IF r% <2 THEN r%=2
IF g% <2 THEN g%=2
IF b%<2 THEN b%=2
IF r%<50 AND g%<50 AND b%<50 THEN skip%=TRUE
IF skip%=FALSE THEN
COLOUR 1,r%,g%,b%:GCOL 1
PROC_triangle(x,y,x%)
ENDIF
NEXT x%
MOVE 0,0
ENDPROC
REM PROC_triangle(x,y,size)- Just a sizable triangle. you set color
DEFPROC_triangle(x,y,s%)
LOCAL c%
c%=s%/2
m%=s%/4
LINE x-c%,y,x,y-m%
LINE x,y-m%,x+c%,y
REM LINE x-c%,y,x+c%,y
LINE x-1+c%,y+1,x,y+s%
LINE x,y+s%,x-c%+1,y+1
ENDPROC
|
« Last Edit: Nov 20th, 2017, 12:49am by michael » |
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: SIN, COS, RAD.. what about depth?
« Reply #1 on: Nov 20th, 2017, 6:06pm » |
|
Hi Michael,
If you want a simple isometric projection, it's relatively easy.
You could reasonably easily amend this by storing all your 3D point coordinates in an array, and then using array arithmetic to calculate the X,Y coordinates for plotting. You could, if you wished, then use those for plotting triangles (or indeed other shapes).
If you want to use different camera points, or show perspective, it all gets a bit more exciting... Hidden line/face removal is also quite tricky...
Maybe Ric will give us a nice example using quaternions!
Best wishes,
D
Code:
MODE 21
ORIGIN 400,400
FOR a=0 TO PI STEP PI/100
CLS
xs=COS(a)
ys=SIN(a)
zs=SQR(2)
r2=SQR(2)
REM Draw axes - note that rather contentiously I've made Z vertical, rather than into the screen
REM Draw x axis in red
GCOL 1
PROCDrawLine(0,0,0,400,0,0)
REM Draw y axis in green
GCOL 2
PROCDrawLine(0,0,0,0,400,0)
REM Draw z axis in blue
GCOL 4
PROCDrawLine(0,0,0,0,0,400)
REM Draw a pyramid in yellow
GCOL 3
PROCDrawLine(100,100,0,500,100,0)
PROCDrawLine(500,100,0,500,500,0)
PROCDrawLine(500,500,0,100,500,0)
PROCDrawLine(100,500,0,100,100,0)
PROCDrawLine(100,100,0,300,300,300)
PROCDrawLine(500,100,0,300,300,300)
PROCDrawLine(500,500,0,300,300,300)
PROCDrawLine(100,500,0,300,300,300)
WAIT 10
NEXT a
END
:
DEFPROCDrawLine(px1,py1,pz1,px2,py2,pz2)
MOVE px1*xs+py1*ys,pz1*zs+(py1*xs-px1*ys)
DRAW px2*xs+py2*ys,pz2*zs+(py2*xs-px2*ys)
ENDPROC
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: SIN, COS, RAD.. what about depth?
« Reply #2 on: Nov 20th, 2017, 7:25pm » |
|
Thank you. I will study this.
|
|
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
|