the number 17
the number 17

Reputation: 33

Converting 2D images to 3D

I was trying to convert 2D images to 3D by rotating them about the axes (like a circle to a sphere). Currently my problem is that suppose I have two functions f(x) and g(x) both in one variable. I wish to make a plot of the functions and use rotation to get 3D plots. Based on the 3D plots I would distinguish between the two.

I think one way could be the work out the exact expressions mathematically for the new functions after rotation, but that can be computationally infeasible for not so reasonable functions. Can someone please suggest a way to do it using suitable softwares?

Upvotes: 1

Views: 2319

Answers (1)

Rorschach
Rorschach

Reputation: 32416

You can do this using rgl package (interface to openGL) in R and the turn3d function

## Define a function (ys must be positive, we are spinning about x-axis)
f <- function(x) 2*exp(-1/2*x) * (cos(pi*x) + sin(pi*x)) + 2
xs <- seq(0, 10, length=1000)
plot(xs, f(xs), type="l")

enter image description here

## Rotate about the x-axis
library(rgl)
res <- turn3d(xs, f(xs))
plot3d(res, alpha=.5)
snapshot3d("temp.png")

enter image description here

Upvotes: 1

Related Questions