Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for computing tangent and normal vectors to segments and trails #113

Merged
merged 5 commits into from
Sep 23, 2013

Conversation

byorgey
Copy link
Member

@byorgey byorgey commented Sep 15, 2013

Opening a pull request so as to have a convenient place to discuss the code, and this feature generally, while I continue to work on it. Please do not merge yet.

For extracting individual segments from trails by parameter.  This
commit only includes instances for lines, need to add loops and
trails.
@byorgey
Copy link
Member Author

byorgey commented Sep 15, 2013

I'm particularly interested to hear what people think of this idiom, where we have a newtype wrapper that exists solely for its instances, and the user ends up writing things of the form

getSegment tr `atParam` 0.6

In this example getSegment is doing nothing but applying a newtype wrapper. It's a bit strange since the getSegment function itself does not really have a semantics; but on the other hand it seems to read fairly well (and lets us reuse the Parametric etc. classes for this). I was planning to use the same idiom with Tangent and Normal wrappers. I'm happy to hear comments, suggestions for alternative approaches, etc.

@jeffreyrosenbluth
Copy link
Member

hmm, yes it is a bit strange and perhaps a tad confusing without knowing ahead of time that it's a newtype wrapper.
What about creating a type class:

class Parametric p => hasSegments p where segAtParam :: ...

then you could write

tr `segAtParam` 0.6

@byorgey
Copy link
Member Author

byorgey commented Sep 15, 2013

That would work, but the downside is that feels like there's some duplication going on, e.g. we would also end up with classes HasTangent with tangentAtParam, and HasNormal with normalAtParam... basically duplicating the Parametric class each time. Note that I want to use the EndValues class as well (since e.g. we can compute the tangents at the endpoints of a segment exactly, without resorting to the general Bézier formula), so then we would have to duplicate that class as well... doesn't feel very nice.

However, this does suggest one possible compromise, as an aid to users: we could provide convenience functions e.g. segAtParam, tangentAtParam, normalAtParam, tangentAtStart, tangentAtEnd, etc. which are defined as e.g. segAtParam x p = getSegment x atParam p. So then we get to reuse the whole Parametric infrastructure and also make it a bit more intuitive for users.

@jeffreyrosenbluth
Copy link
Member

Can't we assume if something has segments it also has tangents and normals.

Sent from my iPhone

On Sep 15, 2013, at 5:33 PM, Brent Yorgey notifications@github.com wrote:

That would work, but the downside is that feels like there's some duplication going on, e.g. we would also end up with classes HasTangent with tangentAtParam, and HasNormal with normalAtParam... basically duplicating the Parametric class each time. Note that I want to use the EndValues class as well (since e.g. we can compute the tangents at the endpoints of a segment exactly, without resorting to the general Bézier formula), so then we would have to duplicate that class as well... doesn't feel very nice.

However, this does suggest one possible compromise, as an aid to users: we could provide convenience functions e.g. segAtParam, tangentAtParam, normalAtParam, tangentAtStart, tangentAtEnd, etc. which are defined as e.g. segAtParam x p = getSegment x atParam p. So then we get to reuse the whole Parametric infrastructure and also make it a bit more intuitive for users.


Reply to this email directly or view it on GitHub.

@byorgey
Copy link
Member Author

byorgey commented Sep 15, 2013

Yes, but the converse may not be true. E.g. 3D objects can be treated as parametric surfaces, and have normals, but they are not composed of segments.

@byorgey
Copy link
Member Author

byorgey commented Sep 23, 2013

OK, this is ready to be merged if someone wants to take a look. I ended up adding functions like tangentAtParam etc., so the user doesn't have to know about the newtype wrappers in order to use it.

@jeffreyrosenbluth
Copy link
Member

This looks good. Does anything need to be re-exported from TwoD.hs?

jeffreyrosenbluth added a commit that referenced this pull request Sep 23, 2013
API for computing tangent and normal vectors to segments and trails
@jeffreyrosenbluth jeffreyrosenbluth merged commit 9d353e0 into master Sep 23, 2013
@byorgey byorgey deleted the tangent branch September 24, 2013 17:21
@byorgey
Copy link
Member Author

byorgey commented Sep 24, 2013

Ah, good catch --- this is not 2D-specific so it should not be re-exported from TwoD.hs, but it should be re-exported from Diagrams.Prelude, which I just pushed: @bba31f0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants