Log in

View Full Version : This works, but I would like something more advanced


Silicate Wielder
February 3rd, 2015, 08:25 PM
Hey guys, I've been testing stuff out in scratch before I test it out in another language, specifically speaking, 3D graphics. I have an equation that works for me but I would like to know what I could use for generating spheres.

Right now I a using the following

W = width
L = Length
A = Angle


X = W cos(A)
Y = L sin(A)


Place pen to draw lines
repeat for the number contained in variable: quality.
go to X (W cos (A)) and Y (L sin(A))
increase value of A by 1
repeat until done
Lift penwith modification to that script I can generate 3-dimensional objects that can be viewed with alteration to pitch, but I was wondering what I can do to allow for tilting, or rotation of the rendered object.

EDIT: Link to demo project: scratch.mit.edu/projects/45762376 (http://www.virtualteen.org/forums/scratch.mit.edu/projects/45762376)

HououinKiyoma
February 3rd, 2015, 08:36 PM
Im not really sure but wouldnt that give you more of an ellipsoid?

Typhlosion
February 3rd, 2015, 08:50 PM
Import a library and call a method like drawSphere(centerX, centerY, centerZ, radius) :P

This is really dependent on what 3D system you are using, though. In reality, a sphere can be just two or three circles (http://www.google.com.br/imgres?imgurl=http://thumbs.dreamstime.com/z/cut-sphere-simple-to-complicated-vector-isolated-36400346.jpg&imgrefurl=http://www.dreamstime.com/stock-photo-cut-cube-simple-to-complicated-vector-isolated-image36324140&h=1387&w=1300&tbnid=5xdTEUDkwGU1hM:&zoom=1&docid=1Wety0ci7_TReM&ei=IHnRVP3gG7iTsQTYz4GoDg&tbm=isch&ved=0CIQBEDMoXjBe), quite a few more (http://www.google.com.br/imgres?imgurl=http://i.stack.imgur.com/yvHKu.png&imgrefurl=http://stackoverflow.com/questions/15584170/draw-sphere-on-timage-control-of-delphi&h=600&w=600&tbnid=TUQDmcg_zXxKnM:&zoom=1&docid=OCQ86pkm0jZO3M&ei=l3nRVKKcGeeHsQSYhIKwBA&tbm=isch&ved=0CKIBEDMoYzBj), or based on triangles (http://www.emagtech.com/wiki/images/4/42/Wire_pic5_tn.png).

Silicate Wielder
February 3rd, 2015, 08:51 PM
Im not really sure but wouldnt that give you more of an ellipsoid?

Well yes, that equation specifically will generate an ellipsoid, but I can use:

L = Length * cos(pitch) + layer
W = width * cos(pitch) + layer

and

X = L cos (A)
Y = W sin (A)

layer would be incremental and increase by 1 for each layer drawn.

HououinKiyoma
February 3rd, 2015, 09:05 PM
Well yes, that equation specifically will generate an ellipsoid, but I can use:

L = Length * cos(pitch) + layer
W = width * cos(pitch) + layer

and

X = L cos (A)
Y = W sin (A)

layer would be incremental and increase by 1 for each layer drawn.

What is pitch? Forgive me for being a n00b

Silicate Wielder
February 3rd, 2015, 09:08 PM
What is pitch? Forgive me for being a n00b

pitch is the tilt of an object fowards or backwards.


Import a library and call a method like drawSphere(centerX, centerY, centerZ, radius) :tongue:

This is really dependent on what 3D system you are using, though. In reality, a sphere can be just two or three circles (http://www.google.com.br/imgres?imgurl=http://thumbs.dreamstime.com/z/cut-sphere-simple-to-complicated-vector-isolated-36400346.jpg&imgrefurl=http://www.dreamstime.com/stock-photo-cut-cube-simple-to-complicated-vector-isolated-image36324140&h=1387&w=1300&tbnid=5xdTEUDkwGU1hM:&zoom=1&docid=1Wety0ci7_TReM&ei=IHnRVP3gG7iTsQTYz4GoDg&tbm=isch&ved=0CIQBEDMoXjBe), quite a few more (http://www.google.com.br/imgres?imgurl=http://i.stack.imgur.com/yvHKu.png&imgrefurl=http://stackoverflow.com/questions/15584170/draw-sphere-on-timage-control-of-delphi&h=600&w=600&tbnid=TUQDmcg_zXxKnM:&zoom=1&docid=OCQ86pkm0jZO3M&ei=l3nRVKKcGeeHsQSYhIKwBA&tbm=isch&ved=0CKIBEDMoYzBj), or based on triangles (http://www.emagtech.com/wiki/images/4/42/Wire_pic5_tn.png).

I didn't know about that command, cool, but that doesn't provide me with the flexibility I need for what it is I am doing with the rendering.

The point of this is just to see if I can write a rudimentary 3D engine, I was just wondering how I could generate a sphere in a manner that the values used can be stored for use later, that way I'm not wasting CPU power constantly recalculating the points, and can just adjust them. and using this method would allow me to generate objects other than spheres, like say a cube, or triangular prism, just by changing the quality value.

It also lets me generate a colored torus in scratch with up to 55 faces and a 20 layers. That's about 110 faces since it has to individually render each ellipsoid in order to generate the image. not only that but I still have enough processing power to add in some basic lighting and shading to the faces. Oh and, that all happens on just a Chromebook.

I just don't think just rendering circles using that command would provide me with the flexibility I need.

so using the stated equations to calculate the coordinates for each point is of better interest for me.