001/* 002 003*/ 004 005package renderer.models; 006 007import java.util.function.DoubleFunction; 008import java.util.function.ToDoubleFunction; // could use this instead 009import java.util.function.DoubleUnaryOperator; // could use this instead 010//https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html 011 012/** 013 Create a wireframe model of a surface of revolution around the y-axis. 014<p> 015 See <a href="https://en.wikipedia.org/wiki/Surface_of_revolution#Rotating_a_function" target="_top"> 016 https://en.wikipedia.org/wiki/Surface_of_revolution#Rotating_a_function</a> 017 018 @see ParametricSurface 019*/ 020public class SurfaceOfRevolution extends ParametricSurface 021{ 022 /** 023 Create a surface of revolution around the y-axis 024 based on a cosine function. 025 */ 026 public SurfaceOfRevolution() 027 { 028 this(t -> 0.5 * (1 + Math.cos(Math.PI * t)), 029 -1.0, 1.0, 49, 49); 030 } 031 032 033 /** 034 Create a surface of revolution around the y-axis 035 with the given radial function, {@code r = r(y)}, 036 the given parameter range along the y-axis, and 037 the given number of circles of latitude. 038 039 @param r radius function 040 @param y1 beginning value along the y-axis 041 @param y2 ending value along the y-axis 042 @param n number of circles of latitude 043 @param k number of lines of longitude 044 */ 045 public SurfaceOfRevolution(DoubleFunction<Double> r, 046 double y1, double y2, 047 int n, int k) 048 { 049 this(r, y1, y2, 0, 2*Math.PI, n, k); 050 } 051 052 053 /** 054 Create a surface of revolution around the y-axis with 055 the given radial function, {@code r = r(y)}, the given 056 angular range for the sector of revolution, the given 057 parameter range along the y-axis, and the given number 058 of circles of latitude. 059 060 @param r radius function 061 @param y1 beginning value along the y-axis 062 @param y2 ending value along the y-axis 063 @param theta1 beginning value of angular parameter range 064 @param theta2 ending value of angular parameter range 065 @param n number of circles of latitude 066 @param k number of lines of longitude 067 */ 068 public SurfaceOfRevolution(DoubleFunction<Double> r, 069 double y1, double y2, 070 double theta1, double theta2, 071 int n, int k) 072 { 073 super( (y,t) -> r.apply(y) * Math.cos(t), 074 (y,t) -> y, 075 (y,t) -> r.apply(y) * Math.sin(t), 076 y1, y2, 077 theta1, theta2, 078 n, k ); 079 } 080 081 082 /** 083 Create a surface of revolution around the y-axis 084 of the given radial parametric curve. 085 086 @param x first component function of the parametric curve 087 @param y second component function of the parametric curve 088 @param s1 beginning parameter value 089 @param s2 ending parameter value 090 @param n number of circles of latitude 091 @param k number of lines of longitude 092 */ 093 public SurfaceOfRevolution(DoubleFunction<Double> x, 094 DoubleFunction<Double> y, 095 double s1, double s2, 096 int n, int k) 097 { 098 this(x, y, s1, s2, 0, 2*Math.PI, n, k ); 099 } 100 101 102 /** 103 Create a surface of revolution around the y-axis 104 of the given radial parametric curve and the given 105 angular range for the sector of revolution. 106 107 @param x first component function of the parametric curve 108 @param y second component function of the parametric curve 109 @param s1 beginning parameter value 110 @param s2 ending parameter value 111 @param theta1 beginning value of angular parameter range 112 @param theta2 ending value of angular parameter range 113 @param n number of circles of latitude 114 @param k number of lines of longitude 115 */ 116 public SurfaceOfRevolution(DoubleFunction<Double> x, 117 DoubleFunction<Double> y, 118 double s1, double s2, 119 double theta1, double theta2, 120 int n, int k) 121 { 122 super( (s,t) -> x.apply(s) * Math.cos(t), 123 (s,t) -> y.apply(s), 124 (s,t) -> x.apply(s) * Math.sin(t), 125 s1, s2, 126 theta1, theta2, 127 n, k ); 128 } 129}//SurfaceOfRevolution